void * thread_func(void * params){ net_client_t * client = (net_client_t *)params; ssize_t received; ssize_t header_size = sizeof(scb_msg_t); ssize_t waitsize; uint32_t flag = MSG_PEEK; while(1) //endless loop { while(1) { flag = MSG_PEEK | MSG_WAITALL; waitsize = header_size; received = recv(client->socket_descriptor,client->read_buffer,waitsize,flag); if(received > 0) { if(((scb_msg_t*)client->read_buffer)->size>client->read_buffer_size) { printf("%s:%d receive error: header->size[%d]>read_buffer_size[%d]!\n", client->remote_host.c_str(),client->remote_port, ((scb_msg_t*)client->read_buffer)->size,client->read_buffer_size); break; } flag = MSG_WAITALL; if(((scb_msg_t*)client->read_buffer)->size==0) { printf("%s:%d receive error: header->size==0, ignoring\n",client->remote_host.c_str(),client->remote_port); received = recv(client->socket_descriptor,client->read_buffer,header_size,flag); continue; } waitsize = (ssize_t)((scb_msg_t*)client->read_buffer)->size; received = recv(client->socket_descriptor,client->read_buffer,waitsize,flag); if(received == waitsize) { if(client->on_data_received) client->on_data_received(client,client->read_buffer,received); } else break; } else break; } client_disconnect(client); sleep(2); client_connect(client); } #if defined(__WINDOWS__) return 0; #else return NULL; #endif}