From 970c212a22d1f1f33780eb58f606008fd6e01e3c Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期一, 30 十一月 2020 18:38:07 +0800 Subject: [PATCH] update --- src/socket/net_mod_socket.c | 249 +++++++++++++++++++++------------- /dev/null | 0 src/socket/net_mod_socket_wrapper.h | 5 test_net_socket/test_net_mod_socket.c | 4 src/socket/net_mod_socket.h | 48 ++++-- src/socket/net_mod_socket_wrapper.c | 10 test_net_socket/Makefile | 2 src/socket/net_mod_server_socket.c | 51 ++++++ 8 files changed, 242 insertions(+), 127 deletions(-) diff --git a/lib/libusgcommon.so b/lib/libusgcommon.so deleted file mode 100644 index 4f1646b..0000000 --- a/lib/libusgcommon.so +++ /dev/null Binary files differ diff --git a/libusgcommon.a b/libusgcommon.a deleted file mode 100644 index 7070160..0000000 --- a/libusgcommon.a +++ /dev/null Binary files differ diff --git a/src/socket/net_mod_server_socket.c b/src/socket/net_mod_server_socket.c index 0808d0b..3b94445 100644 --- a/src/socket/net_mod_server_socket.c +++ b/src/socket/net_mod_server_socket.c @@ -125,10 +125,12 @@ int NetModServerSocket::process_client(int connfd) { net_mod_request_head_t request_head; net_mod_response_head_t response_head; + int ret; char request_head_bs[NET_MODE_REQUEST_HEAD_LENGTH]; void *recv_buf; // char tmp[8196]; int recv_size, response_buf_size; + struct timespec timeout; if (rio_readn(connfd, request_head_bs, NET_MODE_REQUEST_HEAD_LENGTH) != NET_MODE_REQUEST_HEAD_LENGTH) { @@ -136,7 +138,8 @@ } request_head = NetModSocket::decode_request_head(request_head_bs); -// printf("server received request from host = %s:%d\n", request_head.host, request_head.port); +printf("server received request from host = %s:%d, key = %d, timeout=%d,\n", + request_head.host, request_head.port , request_head.key, request_head.timeout); if(request_head.content_length > max_buf) { @@ -152,14 +155,32 @@ return -1; } + if(request_head.mod == REQ_REP) { memcpy(response_head.host, request_head.host, NI_MAXHOST); response_head.port = request_head.port; response_head.key = request_head.key; - if(shmModSocket.sendandrecv_unsafe(buf, request_head.content_length, request_head.key, &recv_buf, &recv_size) != 0) { + + + if(request_head.timeout > 0) { + timeout.tv_sec = request_head.timeout / 1000; + timeout.tv_nsec = (request_head.timeout - timeout.tv_sec * 1000) * 10e6; + + // printf(" timeout.tv_sec = %d, timeout.tv_nsec=%ld\n", timeout.tv_sec, timeout.tv_nsec ); + + ret = shmModSocket.sendandrecv_unsafe_timeout(buf, request_head.content_length, request_head.key, &recv_buf, &recv_size, &timeout); + } + else if(request_head.timeout == 0) { + ret = shmModSocket.sendandrecv_unsafe_nowait(buf, request_head.content_length, request_head.key, &recv_buf, &recv_size); + } + else if(request_head.timeout == -1) { + ret = shmModSocket.sendandrecv_unsafe(buf, request_head.content_length, request_head.key, &recv_buf, &recv_size); + } + + if( ret != 0) { // 娌℃湁瀵瑰簲鐨刱ey - response_head.code = 1; + response_head.code = ret; response_head.content_length = 0; if( rio_writen(connfd, NetModSocket::encode_response_head(response_head), NET_MODE_RESPONSE_HEAD_LENGTH) != NET_MODE_RESPONSE_HEAD_LENGTH ) return -1; @@ -192,7 +213,6 @@ } else if(request_head.mod == BUS) { - // TODO: pub response if(request_head.topic_length > max_topic_buf) { if( (topic_buf = realloc(topic_buf, request_head.topic_length)) == NULL ) { LoggerFactory::getLogger()->error(errno, "NetModServerSocket::process_client realloc topic_buf"); @@ -206,7 +226,28 @@ return -1; } LoggerFactory::getLogger()->debug("====server pub %s===\n", buf); - shmModSocket.pub((char*)topic_buf, request_head.topic_length, buf, request_head.content_length, request_head.key); + memcpy(response_head.host, request_head.host, NI_MAXHOST); + response_head.port = request_head.port; + response_head.key = request_head.key; + + if(request_head.timeout > 0) { + timeout.tv_sec = request_head.timeout / 1000; + timeout.tv_nsec = (request_head.timeout - timeout.tv_sec * 1000) * 10e6; + ret = shmModSocket.pub_timeout((char*)topic_buf, request_head.topic_length, buf, request_head.content_length, request_head.key, &timeout); + } + else if(request_head.timeout == 0) { + ret = shmModSocket.pub_nowait((char*)topic_buf, request_head.topic_length, buf, request_head.content_length, request_head.key); + } + else if(request_head.timeout == -1) { + ret = shmModSocket.pub((char*)topic_buf, request_head.topic_length, buf, request_head.content_length, request_head.key); + } + + response_head.code = ret; + response_head.content_length = 0; + if( rio_writen(connfd, NetModSocket::encode_response_head(response_head), NET_MODE_RESPONSE_HEAD_LENGTH) != NET_MODE_RESPONSE_HEAD_LENGTH ) + return -1; + + } return 0; diff --git a/src/socket/net_mod_socket.c b/src/socket/net_mod_socket.c index 7b9b577..5e0b0b1 100644 --- a/src/socket/net_mod_socket.c +++ b/src/socket/net_mod_socket.c @@ -39,8 +39,8 @@ _sendandrecv_(node_arr, arrlen, send_buf,send_size, recv_arr, recv_arr_size, -1); } int NetModSocket::sendandrecv_timeout(net_node_t *node_arr, int arrlen, void *send_buf, int send_size, - net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int timeout) { - _sendandrecv_(node_arr, arrlen, send_buf,send_size, recv_arr, recv_arr_size, timeout); + net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int msec) { + _sendandrecv_(node_arr, arrlen, send_buf,send_size, recv_arr, recv_arr_size, msec); } int NetModSocket::sendandrecv_nowait(net_node_t *node_arr, int arrlen, void *send_buf, int send_size, net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) { @@ -63,6 +63,7 @@ // printf("open after: %s\n", mapKey); if(connfd < 0) { LoggerFactory::getLogger()->error(errno, "NetModSocket::connect %s:%d ", node->host, node->port); + exit(1); return -1; } @@ -104,12 +105,12 @@ } } - LoggerFactory::getLogger()->debug( "closed %d\n", connfd); + // LoggerFactory::getLogger()->debug( "NetModSocket::close_connect %d\n", connfd); } int NetModSocket::_sendandrecv_(net_node_t *node_arr, int arrlen, void *send_buf, int send_size, - net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int timeout = 5 * 1000) { + net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int msec ) { int i, n, recv_size, connfd; net_node_t *node; @@ -119,7 +120,7 @@ net_mod_request_head_t request_head = {}; - int n_req = 0, n_recv_suc = 0, n_resp; + int n_req = 0, n_recv_suc = 0, n_resp =0; net_mod_recv_msg_t *ret_arr = (net_mod_recv_msg_t *)calloc(arrlen, sizeof(net_mod_recv_msg_t)); @@ -151,13 +152,12 @@ request_head.port = node->port; request_head.key = node->key; request_head.content_length = send_size; - + request_head.timeout = msec; // printf("write_request %s:%d\n", request_head.host, request_head.port); - if(write_request(connfd, request_head, send_buf, send_size) != 0) { + if(write_request(connfd, request_head, send_buf, send_size, NULL, 0) != 0) { LoggerFactory::getLogger()->error("write_request failture %s:%d\n", node->host, node->port); close_connect(mpool, connfd); - // mpool.conns[i].fd = -1; } else { n_req++; } @@ -167,12 +167,10 @@ // printf(" mpool.maxi = %d\n", mpool.maxi); // printf(" n_req = %d\n", n_req); -// int tmp = 0; while(n_resp < n_req) { -// printf(" while %d\n", tmp++); /* Wait for listening/connected descriptor(s) to become ready */ - if( (mpool.nready = poll(mpool.conns, mpool.maxi + 1, timeout) ) <= 0) { + if( (mpool.nready = poll(mpool.conns, mpool.maxi + 1, msec) ) <= 0) { // wirite_set 鍜� read_set 鍦ㄦ寚瀹氭椂闂村唴閮芥病鍑嗗濂� break; } @@ -185,18 +183,17 @@ mpool.nready--; // printf("POLLIN %d\n", connfd); if( (n = read_response(connfd, ret_arr+n_recv_suc)) == 0) { - - // 鎴愬姛鏀跺埌杩斿洖娑堟伅锛屾竻绌鸿鍏ヤ綅 - mpool.conns[i].fd = -1; n_recv_suc++; - } else if(n == -1) { - mpool.conns[i].fd = -1; - close_connect(mpool, connfd); - } else { - mpool.conns[i].fd = -1; - } + // else if(n == -1) { + // // 缃戠粶閿欒 + // } else { + // // 瀵规柟key鏄叧闂殑 + // } + + mpool.conns[i].fd = -1; + close_connect(mpool, connfd); n_resp++; // printf("read response %d\n", n); @@ -217,6 +214,7 @@ } } + //瓒呮椂鍚庯紝鍏抽棴瓒呮椂杩炴帴 for (i = 0; i <= mpool.maxi; i++) { if ( (connfd = mpool.conns[i].fd) > 0 ) { // 鍏抽棴骞舵竻闄ゅ啓鍏ユ垨璇诲彇澶辫触鐨勮繛鎺� @@ -233,6 +231,128 @@ } return n_recv_suc; +} + +int NetModSocket::pub(net_node_t *node_arr, int arrlen, char *topic, int topic_size, void *content, int content_size) { + return _pub_(node_arr, arrlen, topic, topic_size, content, content_size, -1); +} + +int NetModSocket::pub_nowait(net_node_t *node_arr, int arrlen, char *topic, int topic_size, void *content, int content_size) { + return _pub_(node_arr, arrlen, topic, topic_size, content, content_size, 0); +} + +int NetModSocket::pub_timeout(net_node_t *node_arr, int arrlen, char *topic, int topic_size, void *content, int content_size, int msec ) { + return _pub_(node_arr, arrlen, topic, topic_size, content, content_size, msec); +} + + +// int pub(char *topic, int topic_size, void *content, int content_size, int port); + +int NetModSocket::_pub_(net_node_t *node_arr, int arrlen, char *topic, int topic_size, void *content, + int content_size, int timeout) { + int i, connfd; + net_node_t *node; + + net_mod_request_head_t request_head; + net_mod_recv_msg_t recv_msg; + char portstr[32]; + int n_req = 0, n_pub_suc = 0, n_resp = 0; + int ret; + + pool mpool; + init_conn_pool(mpool); + + + for (i = 0; i < arrlen; i++) { + + node = &node_arr[i]; + if(node->host == NULL) { + // 鏈湴鍙戦�� + if(shmModSocket.pub(topic, topic_size, content, content_size, node->key) == 0 ) { + n_pub_suc++; + } + + } else { + sprintf(portstr, "%d", node->port); + if( (connfd = connect(mpool, node)) < 0 ) { + continue; + } + request_head.mod = BUS; + request_head.key = node->key; + request_head.content_length = content_size; + request_head.topic_length = strlen(topic) + 1; + request_head.timeout = timeout; + + if(write_request(connfd, request_head, content, content_size, topic, request_head.topic_length) != 0) { + LoggerFactory::getLogger()->error(" NetModSocket::_pub_ write_request failture %s:%d\n", node->host, node->port); + close_connect(mpool, connfd); + } else { + n_req++; + } + + } + } + + while(n_resp < n_req) + { + /* Wait for listening/connected descriptor(s) to become ready */ + if( (mpool.nready = poll(mpool.conns, mpool.maxi + 1, timeout) ) <= 0) { + // wirite_set 鍜� read_set 鍦ㄦ寚瀹氭椂闂村唴閮芥病鍑嗗濂� + break; + } +// printf("mpool.nready =%d\n", mpool.nready); + for (i = 0; (i <= mpool.maxi) && (mpool.nready > 0); i++) { + if ( (connfd = mpool.conns[i].fd) > 0 ) { + if (mpool.conns[i].revents & POLLIN ) + { + mpool.nready--; +// printf("POLLIN %d\n", connfd); + if( (ret = read_response(connfd, &recv_msg)) == 0) { + + // 鎴愬姛鏀跺埌杩斿洖娑堟伅锛屾竻绌鸿鍏ヤ綅 + mpool.conns[i].fd = -1; + n_pub_suc++; + } + // else if(ret == -1) { + // // 缃戠粶杩炴帴閿欒 + // } else { + // // 瀵规柟鐨刱ey鏄叧闂殑 + // } + mpool.conns[i].fd = -1; + close_connect(mpool, connfd); + n_resp++; +// printf("read response %d\n", n); + + } + + if (mpool.conns[i].revents & POLLOUT ) { + // printf("poll POLLOUT %d\n", connfd); + } + + if (mpool.conns[i].revents & (POLLRDHUP | POLLHUP | POLLERR) ) + { +// printf("poll POLLERR %d\n", connfd); + mpool.nready--; + + mpool.conns[i].fd = -1; + close_connect(mpool, connfd); + } + } + } + } + + //瓒呮椂鍚庯紝鍏抽棴瓒呮椂杩炴帴 + for (i = 0; i <= mpool.maxi; i++) { + if ( (connfd = mpool.conns[i].fd) > 0 ) { + // 鍏抽棴骞舵竻闄ゅ啓鍏ユ垨璇诲彇澶辫触鐨勮繛鎺� + close_connect(mpool, connfd); + mpool.conns[i].fd = -1; + } + } + + mpool.maxi = -1; + + return n_pub_suc; } @@ -356,76 +476,6 @@ } -// int pub(char *topic, int topic_size, void *content, int content_size, int port); - -int NetModSocket::pub(net_node_t *node_arr, int arrlen, char *topic, int topic_size, void *content, int content_size) { - int i, clientfd; - net_node_t *node; - - char *buf; - int max_buf_size, buf_size; - - net_mod_request_head_t request_head; - char portstr[32]; - int nsuc = 0; - - if((buf = (char *)malloc(MAXBUF)) == NULL) { - LoggerFactory::getLogger()->error(errno, "NetModSocket::sendandrecv malloc"); - exit(1); - } else { - max_buf_size = MAXBUF; - } - - for (i = 0; i< arrlen; i++) { - - node = &node_arr[i]; - if(node->host == NULL) { - // 鏈湴鍙戦�� - if(shmModSocket.pub(topic, topic_size, content, content_size, node->key) == 0 ) { - nsuc++; - } - - } else { - sprintf(portstr, "%d", node->port); - clientfd = open_clientfd(node->host, portstr); - if(clientfd < 0) { - continue; - } - - request_head.mod = BUS; - request_head.key = node->key; - request_head.content_length = content_size; - request_head.topic_length = strlen(topic) + 1; - - buf_size = NET_MODE_REQUEST_HEAD_LENGTH + content_size + request_head.topic_length; - - if(max_buf_size < buf_size) { - if( ( buf = (char *)realloc(buf, buf_size)) == NULL) { - LoggerFactory::getLogger()->error(errno, "NetModSocket::pub realloc buf "); - } else { - max_buf_size = buf_size; - } - - } - - memcpy(buf, NetModSocket::encode_request_head(request_head), NET_MODE_REQUEST_HEAD_LENGTH); - memcpy(buf + NET_MODE_REQUEST_HEAD_LENGTH, content, content_size); - memcpy(buf + NET_MODE_REQUEST_HEAD_LENGTH + content_size, topic, request_head.topic_length); - - if(rio_writen(clientfd, buf, buf_size) != buf_size ) { - LoggerFactory::getLogger()->error(errno, "NetModSocket::pub rio_writen conent "); - } else { - nsuc++; - } - close(clientfd); - } - - - } - - free(buf); - return nsuc; -} /** @@ -573,9 +623,8 @@ //====================================================================================== - - -int NetModSocket::write_request(int clientfd, net_mod_request_head_t &request_head, void *send_buf, int send_size) { +int NetModSocket::write_request(int clientfd, net_mod_request_head_t &request_head, + void *content_buf, int content_size, void *topic_buf, int topic_size) { int buf_size; char *buf; @@ -587,7 +636,7 @@ max_buf_size = MAXBUF; } - buf_size = send_size + NET_MODE_REQUEST_HEAD_LENGTH; + buf_size = NET_MODE_REQUEST_HEAD_LENGTH + content_size + topic_size ; if(max_buf_size < buf_size) { if((buf = (char *)realloc(buf, buf_size)) == NULL) { @@ -599,7 +648,9 @@ } memcpy(buf, NetModSocket::encode_request_head(request_head), NET_MODE_REQUEST_HEAD_LENGTH); - memcpy(buf + NET_MODE_REQUEST_HEAD_LENGTH, send_buf, send_size); + memcpy(buf + NET_MODE_REQUEST_HEAD_LENGTH, content_buf, content_size); + if(topic_size != 0 ) + memcpy(buf + NET_MODE_REQUEST_HEAD_LENGTH + content_size, topic_buf, topic_size); if(rio_writen(clientfd, buf, buf_size) != buf_size ) { LoggerFactory::getLogger()->error(errno, "NetModSocket::write_request rio_writen"); @@ -629,7 +680,7 @@ response_head = NetModSocket::decode_response_head(response_head_bs); // printf(">>>> read_response %s\n", response_head.host); if(response_head.code != 0) { - // 瀵规柟娌℃湁瀵瑰簲鐨刱ey + // 浠g悊鏈嶅姟娌¤兘鎴愬姛鍙戦�佺粰瀵瑰簲鐨刱ey return 1; } @@ -696,6 +747,9 @@ tmp_ptr += 4; PUT(tmp_ptr, htonl(head.topic_length)); + + tmp_ptr += 4; + PUT_INT32(tmp_ptr, htonl(head.timeout)); return headbs; @@ -722,6 +776,9 @@ tmp_ptr += 4; head.topic_length = ntohl(GET(tmp_ptr)); + + tmp_ptr += 4; + head.timeout = ntohl(GET_INT32(tmp_ptr)); return head; } diff --git a/src/socket/net_mod_socket.h b/src/socket/net_mod_socket.h index df5aa7f..5e7b7b7 100644 --- a/src/socket/net_mod_socket.h +++ b/src/socket/net_mod_socket.h @@ -9,11 +9,8 @@ #define GET(p) (*(uint32_t *)(p)) #define PUT(p, val) (*(uint32_t *)(p) = (val)) - -#define ERROR_NET_MOD_SOCKET_ADDR_IN_USE 1 - - - +#define GET_INT32(p) (*(int32_t *)(p)) +#define PUT_INT32(p, val) (*(int32_t *)(p) = (val)) class NetModServerSocket; @@ -24,25 +21,30 @@ int key; }; -#define NET_MODE_REQUEST_HEAD_LENGTH (NI_MAXHOST + 5 * sizeof(uint32_t)) +#define NET_MODE_REQUEST_HEAD_LENGTH (NI_MAXHOST + 6 * sizeof(uint32_t)) + +// 璇锋眰澶� struct net_mod_request_head_t { uint32_t mod; char host[NI_MAXHOST]; uint32_t port; uint32_t key; - uint32_t content_length; - uint32_t topic_length; + uint32_t content_length; // 璇锋眰鍐呭 + uint32_t topic_length; // 璇锋眰涓婚 + int32_t timeout; // -1 block, 0 nowait , > 0 timeout }; #define NET_MODE_RESPONSE_HEAD_LENGTH (NI_MAXHOST + 4 * sizeof(uint32_t)) + +// 搴旂瓟澶� struct net_mod_response_head_t { // socket_mod_t mod; char host[NI_MAXHOST]; uint32_t port; uint32_t key; - uint32_t code; + uint32_t code; //杩斿洖鍊�, 0 涓烘垚鍔� uint32_t content_length; }; @@ -84,11 +86,12 @@ int connect(pool& mpool, net_node_t* node); void close_connect(pool& mpool , int connfd); int read_response(int clientfd, net_mod_recv_msg_t *recv_msg); - int write_request(int clientfd, net_mod_request_head_t &request_head, void *send_buf, int send_size); + int write_request(int clientfd, net_mod_request_head_t &request_head, void *send_buf, int send_size, void *topic_buf, int topic_size); int _sendandrecv_(net_node_t *node_arr, int node_arr_len, void *send_buf, int send_size, net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int timeout); + int _pub_(net_node_t *node_arr, int arrlen, char *topic, int topic_size, void *content, int content_size, int timeout) ; public: @@ -184,6 +187,21 @@ */ int start_bus(); + + /** + * 鍚憂ode_arr 涓殑鎵�鏈夌綉缁滆妭鐐瑰彂甯冩秷鎭� + * @node_arr 缃戠粶鑺傜偣缁�, @node_arr_len璇ユ暟缁勯暱搴� + * @topic 涓婚锛孈topic_size 璇ヤ富棰樼殑闀垮害 + * @content 鍐呭锛孈content_size 鍐呭闀垮害 + * @return 鎴愬姛鍙戝竷鐨勮妭鐐圭殑涓暟 + */ + int pub(net_node_t *node_arr, int arrlen, char *topic, int topic_size, void *content, int content_size) ; + + int pub_nowait(net_node_t *node_arr, int arrlen, char *topic, int topic_size, void *content, int content_size); + /** + * @msec 姣 锛堝崈鍒嗕箣涓�绉掞級 + */ + int pub_timeout(net_node_t *node_arr, int arrlen, char *topic, int topic_size, void *content, int content_size, int msec); /** * 璁㈤槄鎸囧畾涓婚 * @topic 涓婚 @@ -220,14 +238,8 @@ - /** - * 鍚憂ode_arr 涓殑鎵�鏈夌綉缁滆妭鐐瑰彂甯冩秷鎭� - * @node_arr 缃戠粶鑺傜偣缁�, @node_arr_len璇ユ暟缁勯暱搴� - * @topic 涓婚锛孈topic_size 璇ヤ富棰樼殑闀垮害 - * @content 鍐呭锛孈content_size 鍐呭闀垮害 - * @return 鎴愬姛鍙戝竷鐨勮妭鐐圭殑涓暟 - */ - int pub(net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size); + + /** * 鑾峰彇soket key diff --git a/src/socket/net_mod_socket_wrapper.c b/src/socket/net_mod_socket_wrapper.c index 7e7ed92..1434033 100644 --- a/src/socket/net_mod_socket_wrapper.c +++ b/src/socket/net_mod_socket_wrapper.c @@ -125,11 +125,13 @@ net_mod_socket_t *sockt = (net_mod_socket_t *)_socket; return sockt->sockt->pub(node_arr, node_arr_len, topic, topic_size, content, content_size); } -int net_mod_socket_pub_timeout(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size, int timeout){ - return 0; +int net_mod_socket_pub_timeout(void *_socket, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size, int msec){ + net_mod_socket_t *sockt = (net_mod_socket_t *)_socket; + return sockt->sockt->pub_timeout(node_arr, node_arr_len, topic, topic_size, content, content_size, msec); } -int net_mod_socket_pub_nowait(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size){ - return 0; +int net_mod_socket_pub_nowait(void *_socket, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size){ + net_mod_socket_t *sockt = (net_mod_socket_t *)_socket; + return sockt->sockt->pub_nowait(node_arr, node_arr_len, topic, topic_size, content, content_size); } diff --git a/src/socket/net_mod_socket_wrapper.h b/src/socket/net_mod_socket_wrapper.h index 830a992..a2f82e1 100644 --- a/src/socket/net_mod_socket_wrapper.h +++ b/src/socket/net_mod_socket_wrapper.h @@ -103,7 +103,10 @@ * @return 鎴愬姛鍙戝竷鐨勮妭鐐圭殑涓暟 */ int net_mod_socket_pub(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size); -int net_mod_socket_pub_timeout(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size, int timeout); +/* + * @msec 姣锛堝崈鍒嗕箣涓�绉掞級 + */ +int net_mod_socket_pub_timeout(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size, int msec); int net_mod_socket_pub_nowait(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size); /** diff --git a/test_net_socket/Makefile b/test_net_socket/Makefile index 0d8505f..aea971a 100644 --- a/test_net_socket/Makefile +++ b/test_net_socket/Makefile @@ -3,7 +3,7 @@ PLATFORM=$(shell $(ROOT)/systype.sh) include $(ROOT)/Make.defines.$(PLATFORM) -RPATH += -Wl,-rpath=$(ROOT)/lib:$(DEST)/lib +#RPATH += -Wl,-rpath=$(ROOT)/lib:$(DEST)/lib # 寮�婧愬伐鍏峰寘璺緞 LDDIR += -L$(DEST)/lib diff --git a/test_net_socket/test_net_mod_socket.c b/test_net_socket/test_net_mod_socket.c index 15c9e55..77237ce 100644 --- a/test_net_socket/test_net_mod_socket.c +++ b/test_net_socket/test_net_mod_socket.c @@ -87,8 +87,8 @@ if (fgets(content, MAXLINE, stdin) != NULL) { // 鏀跺埌娑堟伅鐨勮妭鐐瑰嵆浣挎病鏈夊搴旂殑淇℃伅锛� 涔熻鍥炲涓�涓〃绀烘棤鐨勬秷鎭�,鍚﹀垯浼氫竴鐩寸瓑寰� - n = net_mod_socket_sendandrecv_timeout(client, node_arr, node_arr_size, content, - strlen(content), &recv_arr, &recv_arr_size, 5000); + n = net_mod_socket_sendandrecv(client, node_arr, node_arr_size, content, + strlen(content), &recv_arr, &recv_arr_size); printf("send %d nodes\n", n); for(i=0; i<recv_arr_size; i++) { printf("host:%s, port: %d, key:%d, content: %s\n", -- Gitblit v1.8.0