mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-27 09:58:45 +01:00
pass, save and restore port; read several messages at once
This commit is contained in:
parent
762945857e
commit
d29840434f
4 changed files with 45 additions and 31 deletions
|
@ -57,6 +57,7 @@ void deleteGame( sqlite3* pDb, sqlite3_int64 rowid );
|
|||
#define KEY_RDEVID "RDEVID"
|
||||
#define KEY_LDEVID "LDEVID"
|
||||
#define KEY_SMSPHONE "SMSPHONE"
|
||||
#define KEY_SMSPORT "SMSPORT"
|
||||
|
||||
void db_store( sqlite3* dbp, const gchar* key, const gchar* value );
|
||||
XP_Bool db_fetch( sqlite3* dbp, const gchar* key, gchar* buf, gint buflen );
|
||||
|
|
|
@ -688,13 +688,21 @@ gtkmain( LaunchParams* params )
|
|||
} else if ( !phone && db_fetch( params->pDb, KEY_SMSPHONE, buf, VSIZE(buf) ) ) {
|
||||
params->connInfo.sms.phone = phone = buf;
|
||||
}
|
||||
if ( !!phone ) {
|
||||
XP_U16 port = params->connInfo.sms.port;
|
||||
gchar portbuf[8];
|
||||
if ( 0 < port ) {
|
||||
sprintf( portbuf, "%d", port );
|
||||
db_store( params->pDb, KEY_SMSPORT, portbuf );
|
||||
} else if ( db_fetch( params->pDb, KEY_SMSPORT, portbuf, VSIZE(portbuf) ) ) {
|
||||
params->connInfo.sms.port = port = atoi( portbuf );
|
||||
}
|
||||
if ( !!phone && 0 < port ) {
|
||||
SMSProcs smsProcs = {
|
||||
.socketChanged = gtkSocketChanged,
|
||||
.inviteReceived = smsInviteReceived,
|
||||
.msgReceived = smsMsgReceived,
|
||||
};
|
||||
linux_sms2_init( params, phone, &smsProcs, &apg );
|
||||
linux_sms2_init( params, phone, port, &smsProcs, &apg );
|
||||
} else {
|
||||
XP_LOGF( "not activating SMS: I don't have a phone" );
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ static void
|
|||
makeQueuePath( const XP_UCHAR* phone, XP_U16 port,
|
||||
XP_UCHAR* path, XP_U16 pathlen )
|
||||
{
|
||||
XP_ASSERT( 0 != port );
|
||||
snprintf( path, pathlen, "%s/%s_%d", SMS_DIR, phone, port );
|
||||
}
|
||||
|
||||
|
@ -271,8 +272,6 @@ sms2_receive( void* closure, int socket )
|
|||
XP_ASSERT( !!params->sms2Storage );
|
||||
LinSMS2Data* storage = getStorage( params );
|
||||
|
||||
XP_S16 nRead = -1;
|
||||
|
||||
XP_ASSERT( socket == storage->fd );
|
||||
|
||||
lock_queue2( storage );
|
||||
|
@ -282,37 +281,44 @@ sms2_receive( void* closure, int socket )
|
|||
XP_U8 buffer[sizeof(struct inotify_event) + 16];
|
||||
if ( 0 > read( socket, buffer, sizeof(buffer) ) ) {
|
||||
}
|
||||
char shortest[256] = { '\0' };
|
||||
GDir* dir = g_dir_open( storage->myQueue, 0, NULL );
|
||||
XP_LOGF( "%s: opening %s", __func__, storage->myQueue );
|
||||
for ( ; ; ) {
|
||||
const gchar* name = g_dir_read_name( dir );
|
||||
if ( NULL == name ) {
|
||||
XP_S16 nRead = -1;
|
||||
char shortest[256] = { '\0' };
|
||||
GDir* dir = g_dir_open( storage->myQueue, 0, NULL );
|
||||
XP_LOGF( "%s: opening %s", __func__, storage->myQueue );
|
||||
for ( ; ; ) {
|
||||
const gchar* name = g_dir_read_name( dir );
|
||||
if ( NULL == name ) {
|
||||
break;
|
||||
} else if ( 0 == strcmp( name, LOCK_FILE ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( !shortest[0] || 0 < strcmp( shortest, name ) ) {
|
||||
snprintf( shortest, sizeof(shortest), "%s", name );
|
||||
}
|
||||
}
|
||||
g_dir_close( dir );
|
||||
|
||||
uint8_t buf[256];
|
||||
CommsAddrRec fromAddr = {0};
|
||||
if ( !!shortest[0] ) {
|
||||
nRead = decodeAndDelete2( storage, shortest, buf,
|
||||
sizeof(buf), &fromAddr );
|
||||
}
|
||||
|
||||
unlock_queue2( storage );
|
||||
|
||||
if ( 0 < nRead ) {
|
||||
parseAndDispatch( params, buf, nRead, &fromAddr );
|
||||
lock_queue2( storage );
|
||||
} else {
|
||||
break;
|
||||
} else if ( 0 == strcmp( name, LOCK_FILE ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( !shortest[0] || 0 < strcmp( shortest, name ) ) {
|
||||
snprintf( shortest, sizeof(shortest), "%s", name );
|
||||
}
|
||||
}
|
||||
g_dir_close( dir );
|
||||
|
||||
uint8_t buf[256];
|
||||
CommsAddrRec fromAddr = {0};
|
||||
if ( !!shortest[0] ) {
|
||||
nRead = decodeAndDelete2( storage, shortest, buf, sizeof(buf), &fromAddr );
|
||||
}
|
||||
|
||||
unlock_queue2( storage );
|
||||
|
||||
if ( 0 < nRead ) {
|
||||
parseAndDispatch( params, buf, nRead, &fromAddr );
|
||||
}
|
||||
} /* sms2_receive */
|
||||
|
||||
void
|
||||
linux_sms2_init( LaunchParams* params, const gchar* phone,
|
||||
linux_sms2_init( LaunchParams* params, const gchar* phone, XP_U16 port,
|
||||
const SMSProcs* procs, void* procClosure )
|
||||
{
|
||||
XP_ASSERT( !!phone );
|
||||
|
@ -322,8 +328,7 @@ linux_sms2_init( LaunchParams* params, const gchar* phone,
|
|||
storage->procs = procs;
|
||||
storage->procClosure = procClosure;
|
||||
|
||||
makeQueuePath( phone, params->connInfo.sms.port,
|
||||
storage->myQueue, sizeof(storage->myQueue) );
|
||||
makeQueuePath( phone, port, storage->myQueue, sizeof(storage->myQueue) );
|
||||
XP_LOGF( "%s: my queue: %s", __func__, storage->myQueue );
|
||||
storage->port = params->connInfo.sms.port;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ typedef struct _SMSProcs {
|
|||
|
||||
|
||||
void linux_sms2_init( LaunchParams* params, const gchar* phone,
|
||||
const SMSProcs* procs, void* procClosure );
|
||||
XP_U16 port, const SMSProcs* procs, void* procClosure );
|
||||
XP_S16 linux_sms2_send( LaunchParams* params, const XP_U8* buf,
|
||||
XP_U16 buflen, const XP_UCHAR* phone, XP_U16 port,
|
||||
XP_U32 gameID );
|
||||
|
|
Loading…
Reference in a new issue