@@ -116,6 +116,7 @@ typedef struct {
116
116
int connected ; // are we connected to the EventID server
117
117
char * host ;
118
118
char * service ;
119
+ char ever_got_id ;
119
120
} context_t ;
120
121
121
122
@@ -236,6 +237,7 @@ static int ID_connect_to(const char *address, const char *service)
236
237
int sock , c , err , opt = 1 ;
237
238
struct addrinfo * a ;
238
239
240
+ fprintf (stdout , "Trying to connect to %s\r\n" , address );
239
241
sock = socket (AF_INET , SOCK_STREAM , 0 );
240
242
if (sock < 0 ) {
241
243
fprintf (stderr , "ID_connect() socket failed: %s\r\n" , strerror (errno ));
@@ -302,7 +304,7 @@ static int ID_connect(context_t *ctx)
302
304
// and stores it in our ringbuffer
303
305
//
304
306
// runs in a sub-thread
305
- static void * ID_collect (void * nyx )
307
+ /* _Noreturn */ static void * ID_collect (void * nyx )
306
308
{
307
309
context_t * ctx = (context_t * )nyx ;
308
310
char buff [ID_MESSAGE_SIZE ];
@@ -384,7 +386,7 @@ static void* ID_collect(void* nyx)
384
386
ctx -> events [ctx -> events_idx ].offset = offset ;
385
387
}
386
388
printf ("Connected to EventID server and getting data\r\n" );
387
-
389
+ ctx -> ever_got_id = 1 ;
388
390
}
389
391
ctx -> events [ctx -> events_idx ].t .tv_sec = tv .tv_sec ;
390
392
ctx -> events [ctx -> events_idx ].t .tv_usec = tv .tv_usec ;
@@ -446,7 +448,7 @@ static void deliver_id(context_t *ctx)
446
448
return ;
447
449
}
448
450
449
- printf ("waiting for connections...\r\n" );
451
+ printf ("Waiting for incoming connections...\r\n" );
450
452
451
453
for (;;) { // main accept() loop
452
454
sin_size = sizeof (client_addr );
@@ -516,6 +518,10 @@ int main(int argc, char *argv[])
516
518
// connect to the EventID Server to gather information
517
519
pthread_create (& t , NULL , & ID_collect , ctx );
518
520
#endif
521
+ // active wait for connection *cough*
522
+ do sleep (1 );
523
+ while (!ctx -> ever_got_id );
524
+
519
525
// deliver EventIDs with less jitter to users
520
526
deliver_id (ctx );
521
527
0 commit comments