diff --git a/xwords4/linux/relaycon.c b/xwords4/linux/relaycon.c index a56389de0..491d1a3af 100644 --- a/xwords4/linux/relaycon.c +++ b/xwords4/linux/relaycon.c @@ -29,6 +29,7 @@ #include "comtypes.h" typedef struct _RelayConStorage { + pthread_t mainThread; int socket; RelayConnProcs procs; void* procsClosure; @@ -202,6 +203,8 @@ relaycon_init( LaunchParams* params, const RelayConnProcs* procs, XP_MEMCPY( &storage->procs, procs, sizeof(storage->procs) ); storage->procsClosure = procsClosure; + storage->mainThread = pthread_self(); + storage->socket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); (*procs->socketAdded)( storage, storage->socket, relaycon_receive ); @@ -360,6 +363,12 @@ relaycon_deleted( LaunchParams* params, const XP_UCHAR* devID, sendIt( storage, tmpbuf, indx ); } +static XP_Bool +onMainThread( RelayConStorage* storage ) +{ + return storage->mainThread = pthread_self(); +} + static void sendAckIf( RelayConStorage* storage, const MsgHeader* header ) { @@ -579,6 +588,7 @@ static void* postThread( void* arg ) { PostArgs* pa = (PostArgs*)arg; + XP_ASSERT( !onMainThread(pa->storage) ); char* data = g_base64_encode( pa->msgbuf, pa->len ); struct json_object* jobj = json_object_new_object(); struct json_object* jstr = json_object_new_string(data);