Commit af8ecc51 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

mulithreading harshly tested - success

parent 9c51a1ed
No preview for this file type
...@@ -110,7 +110,7 @@ int main (int argc, char **argv) { ...@@ -110,7 +110,7 @@ int main (int argc, char **argv) {
} }
gch.server.sin_family = AF_INET; gch.server.sin_family = AF_INET;
gch.server.sin_port = htons(54345); gch.server.sin_port = htons(54445);
gch.server.sin_addr.s_addr = INADDR_ANY; gch.server.sin_addr.s_addr = INADDR_ANY;
if (bind(gch.server_desc, (struct sockaddr *) &gch.server, sizeof(gch.server)) < 0) { if (bind(gch.server_desc, (struct sockaddr *) &gch.server, sizeof(gch.server)) < 0) {
...@@ -126,15 +126,15 @@ int main (int argc, char **argv) { ...@@ -126,15 +126,15 @@ int main (int argc, char **argv) {
pthread_mutex_init(&mutex, NULL); pthread_mutex_init(&mutex, NULL);
while (working) { while (working) {
gcom_ch_request_t req; gcom_ch_request_t *req = (gcom_ch_request_t *)malloc(sizeof(gcom_ch_request_t));
memset(&req, 0x0, sizeof(gcom_ch_request_t)); memset(req, 0x0, sizeof(gcom_ch_request_t));
memcpy(&(req.gch), &gch, sizeof(gcom_ch_t)); memcpy(&req->gch, &gch, sizeof(gcom_ch_t));
printf("listenninig...\n"); printf("listenninig...\n");
req.gch.sock_len = sizeof(req.gch.client); req->gch.sock_len = sizeof(req->gch.client);
if (recv_gcom_ch(&req.gch, req.packet, &req.packet_length, DEVICE_DATA_MAX_LENGTH)) { if (recv_gcom_ch(&req->gch, req->packet, &req->packet_length, DEVICE_DATA_MAX_LENGTH)) {
task_queue_enqueue(tq, process_packet, &req); task_queue_enqueue(tq, process_packet, req);
} else { } else {
fprintf(stderr, "payload decode error\n"); fprintf(stderr, "payload decode error\n");
...@@ -339,6 +339,8 @@ void process_packet(void *request) { ...@@ -339,6 +339,8 @@ void process_packet(void *request) {
} else { } else {
fprintf(stderr, "payload decode error\n"); fprintf(stderr, "payload decode error\n");
} }
free(req);
} }
void gateway_protocol_data_send_payload_decode( void gateway_protocol_data_send_payload_decode(
...@@ -466,6 +468,7 @@ int recv_gcom_ch(gcom_ch_t *gch, uint8_t *pck, uint8_t *pck_length, uint16_t pck ...@@ -466,6 +468,7 @@ int recv_gcom_ch(gcom_ch_t *gch, uint8_t *pck, uint8_t *pck_length, uint16_t pck
} else { } else {
*pck_length = ret; *pck_length = ret;
} }
return ret; return ret;
} }
/* connection handler for multithreading version */ /* connection handler for multithreading version */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment