multi_socket_client.c: code refine

pull/37/head
YuQing 2019-09-22 21:31:55 +08:00
parent 93ca7b42cd
commit cd4a1c3959
3 changed files with 13 additions and 4 deletions

View File

@ -3,6 +3,7 @@
Version 1.41 2019-09-22 Version 1.41 2019-09-22
* change CIDR network_bits range from [16, 32) to [10, 32) * change CIDR network_bits range from [16, 32) to [10, 32)
* ini_file_reader.c: fix empty string compare * ini_file_reader.c: fix empty string compare
* multi_socket_client.c: code refine
Version 1.40 2018-11-09 Version 1.40 2018-11-09
* add function conn_pool_parse_server_info and conn_pool_load_server_info * add function conn_pool_parse_server_info and conn_pool_load_server_info

View File

@ -138,6 +138,7 @@ static int fast_multi_sock_client_do_send(FastMultiSockClient *client,
entry->remain -= bytes; entry->remain -= bytes;
if (entry->remain == 0) { if (entry->remain == 0) {
entry->remain = client->header_length; //to recv pkg header entry->remain = client->header_length; //to recv pkg header
entry->recv_stage = fast_multi_sock_stage_recv_header;
entry->io_callback = fast_multi_sock_client_do_recv; entry->io_callback = fast_multi_sock_client_do_recv;
if (ioevent_modify(&client->ioevent, entry->conn->sock, if (ioevent_modify(&client->ioevent, entry->conn->sock,
IOEVENT_READ, entry) != 0) IOEVENT_READ, entry) != 0)
@ -254,8 +255,10 @@ static int fast_multi_sock_client_do_recv(FastMultiSockClient *client,
entry->recv_buffer.length += bytes; entry->recv_buffer.length += bytes;
entry->remain -= bytes; entry->remain -= bytes;
if (entry->remain == 0 && entry->recv_buffer.length == client->header_length) { if (entry->remain == 0 && entry->recv_stage == fast_multi_sock_stage_recv_header) {
int body_length; int body_length;
entry->recv_stage = fast_multi_sock_stage_recv_body;
body_length = client->get_body_length_func(&entry->recv_buffer); body_length = client->get_body_length_func(&entry->recv_buffer);
if (body_length < 0) { if (body_length < 0) {
logError("file: "__FILE__", line: %d, " logError("file: "__FILE__", line: %d, "
@ -265,6 +268,10 @@ static int fast_multi_sock_client_do_recv(FastMultiSockClient *client,
result = EINVAL; result = EINVAL;
break; break;
} }
else if (body_length == 0) {
break;
}
if ((result=fast_buffer_check(&entry->recv_buffer, body_length)) != 0) { if ((result=fast_buffer_check(&entry->recv_buffer, body_length)) != 0) {
break; break;
} }

View File

@ -22,9 +22,9 @@
#include "ioevent.h" #include "ioevent.h"
typedef enum { typedef enum {
fast_multi_sock_stage_send = 'S', fast_multi_sock_stage_recv_header = 'H',
fast_multi_sock_stage_recv = 'R' fast_multi_sock_stage_recv_body = 'B'
} FastMultiSockStage; } FastMultiSockRecvStage;
struct fast_multi_sock_client; struct fast_multi_sock_client;
struct fast_multi_sock_entry; struct fast_multi_sock_entry;
@ -43,6 +43,7 @@ typedef struct fast_multi_sock_entry {
FastBuffer recv_buffer; //recv buffer FastBuffer recv_buffer; //recv buffer
int error_no; //0 for success, != 0 fail int error_no; //0 for success, != 0 fail
int remain; //remain bytes, for internal use int remain; //remain bytes, for internal use
FastMultiSockRecvStage recv_stage;
bool done; //for internal use bool done; //for internal use
} FastMultiSockEntry; } FastMultiSockEntry;