diff --git a/lib/sxmplv2.c b/lib/sxmplv2.c index 72679db..5e53d8a 100644 --- a/lib/sxmplv2.c +++ b/lib/sxmplv2.c @@ -834,7 +834,7 @@ static void *__sxmpl_thread(void *b) } else if(mhead->attr & SXMSG_LINK) { /* link layer messages */ if(mhead->attr & SXMSG_CLOSED) goto __finish; /* close the link */ if(mhead->attr & SXMSG_PULSE) { /* it's a link pulse messages */ - /* TODO: syncronization and so on */ + /* TODO: other service messages */ if(mhead->opcode == SXE_RAPIDMSG) { /* custom pulse */ sx = parse_sexp(bbuf, mhead->payload_length); if(sx && co->ssys->on_pulse) co->ssys->on_pulse(co, sx); @@ -1279,7 +1279,12 @@ sxlink_t *sxlink_connect(sxhub_t *ssys, const char *host, } /* SSL handshake */ - co->ssl = SSL_new(ssys->ctx); /* TODO: checkout for it */ + co->ssl = SSL_new(ssys->ctx); + if(!co->ssl) { + close(sck); + r = SXE_ENOMEM; + goto __fail; + } SSL_set_fd(co->ssl, sck); /* attach connected socket */ SSL_set_connect_state(co->ssl); if(SSL_connect(co->ssl) == -1) { @@ -1410,6 +1415,8 @@ sxlink_t *sxlink_connect(sxhub_t *ssys, const char *host, int sxlink_close(sxlink_t *co) { sxmplv2_head_t mhead; + pthread_t curr = pthread_self(); + int i; memset(&mhead, 0, sizeof(sxmplv2_head_t)); /* setup header */ @@ -1422,8 +1429,9 @@ int sxlink_close(sxlink_t *co) /* we will not wait anything */ co->flags |= SXMP_CLOSED; - /* TODO: wait until all threads will finish */ - usleep(20000); + for(i = 0; i < 8; i++) { + if(!pthread_equal(curr, co->thrd_poll[i])) pthread_join(co->thrd_poll[i], NULL); + } return SXE_SUCCESS; }