diff options
-rw-r--r-- | include/comms.h | 6 | ||||
-rw-r--r-- | src/libs/zbxcomms/comms.c | 30 | ||||
-rw-r--r-- | src/libs/zbxsysinfo/common/http.c | 2 | ||||
-rw-r--r-- | src/zabbix_agent/active.c | 2 | ||||
-rw-r--r-- | src/zabbix_get/zabbix_get.c | 2 | ||||
-rw-r--r-- | src/zabbix_server/poller/checks_agent.c | 2 |
6 files changed, 29 insertions, 15 deletions
diff --git a/include/comms.h b/include/comms.h index 0b9ca98d..dfebdbc4 100644 --- a/include/comms.h +++ b/include/comms.h @@ -74,7 +74,11 @@ void zbx_tcp_unaccept(zbx_sock_t *s); void zbx_tcp_free(zbx_sock_t *s); -int zbx_tcp_recv(zbx_sock_t *s, char **data); +#define ZBX_TCP_READ_UNTIL_CLOSE 0x01 + +#define zbx_tcp_recv(s, data) zbx_tcp_recv_ext(s, data, 0) + +int zbx_tcp_recv_ext(zbx_sock_t *s, char **data, unsigned char flags); int zbx_tcp_check_security( zbx_sock_t *s, diff --git a/src/libs/zbxcomms/comms.c b/src/libs/zbxcomms/comms.c index f26751f5..6fe63320 100644 --- a/src/libs/zbxcomms/comms.c +++ b/src/libs/zbxcomms/comms.c @@ -31,8 +31,6 @@ # define ZBX_TCP_WRITE(s, b, bl) ((ssize_t)send((s), (b), (bl), 0)) # define ZBX_TCP_READ(s, b, bl) ((ssize_t)recv((s), (b), (bl), 0)) -# define ZBX_TCP_READ_EOF(readed, requested) ( 0 == (readed) ) - # define ZBX_TCP_ERROR SOCKET_ERROR # define ZBX_SOCK_ERROR INVALID_SOCKET @@ -43,8 +41,6 @@ # define ZBX_TCP_WRITE(s, b, bl) ((ssize_t)write((s), (b), (bl))) # define ZBX_TCP_READ(s, b, bl) ((ssize_t)read((s), (b), (bl))) -# define ZBX_TCP_READ_EOF(readed, requested) ( (requested) > (readed) || 0 == (readed) ) - # define ZBX_TCP_ERROR -1 # define ZBX_SOCK_ERROR -1 @@ -533,11 +529,11 @@ void zbx_tcp_free(zbx_sock_t *s) * Comments: * * * ******************************************************************************/ -int zbx_tcp_recv(zbx_sock_t *s, char **data) +int zbx_tcp_recv_ext(zbx_sock_t *s, char **data, unsigned char flags) { #define ZBX_BUF_LEN ZBX_STAT_BUF_LEN*8 - ssize_t nbytes; + ssize_t nbytes, left; ssize_t read_bytes; int allocated, offset; @@ -568,13 +564,23 @@ int zbx_tcp_recv(zbx_sock_t *s, char **data) if( ZBX_TCP_ERROR != nbytes ) { + left = sizeof(s->buf_stat) - read_bytes - 1; + /* fill static buffer */ - while( read_bytes < expected_len && (sizeof(s->buf_stat) - read_bytes - 1) > 0 - && ZBX_TCP_ERROR != (nbytes = ZBX_TCP_READ( s->socket, s->buf_stat + read_bytes, sizeof(s->buf_stat) - read_bytes - 1))) + while( read_bytes < expected_len && left > 0 + && ZBX_TCP_ERROR != (nbytes = ZBX_TCP_READ( s->socket, s->buf_stat + read_bytes, left))) { read_bytes += nbytes; - if( ZBX_TCP_READ_EOF(nbytes, sizeof(s->buf_stat) - read_bytes - 1) ) break; + + if( flags & ZBX_TCP_READ_UNTIL_CLOSE ) { + if(nbytes == 0) break; + } else { + if(nbytes < left) break; + } + + left -= nbytes; } + s->buf_stat[read_bytes] = '\0'; if( (sizeof(s->buf_stat) - 1) == read_bytes) /* static buffer is full */ { @@ -594,7 +600,11 @@ int zbx_tcp_recv(zbx_sock_t *s, char **data) zbx_snprintf_alloc(&(s->buf_dyn), &allocated, &offset, sizeof(s->buf_stat), "%s", s->buf_stat); read_bytes += nbytes; - if( ZBX_TCP_READ_EOF(nbytes, sizeof(s->buf_stat) - 1) ) break; + if( flags & ZBX_TCP_READ_UNTIL_CLOSE ) { + if(nbytes == 0) break; + } else { + if(nbytes < sizeof(s->buf_stat) - 1) break; + } } *data = s->buf_dyn; diff --git a/src/libs/zbxsysinfo/common/http.c b/src/libs/zbxsysinfo/common/http.c index 6fd170b7..025a9b1b 100644 --- a/src/libs/zbxsysinfo/common/http.c +++ b/src/libs/zbxsysinfo/common/http.c @@ -46,7 +46,7 @@ static int get_http_page(char *host, char *param, unsigned short port, char *buf if( SUCCEED == (ret = zbx_tcp_send_raw(&s, request)) ) { - if( SUCCEED == (ret = zbx_tcp_recv(&s, &buf)) ) + if( SUCCEED == (ret = zbx_tcp_recv_ext(&s, &buf, ZBX_TCP_READ_UNTIL_CLOSE)) ) { zbx_rtrim(buf, "\n\r\0"); diff --git a/src/zabbix_agent/active.c b/src/zabbix_agent/active.c index b9fcfa4d..ac36be0a 100644 --- a/src/zabbix_agent/active.c +++ b/src/zabbix_agent/active.c @@ -281,7 +281,7 @@ static int get_active_checks( { zabbix_log(LOG_LEVEL_DEBUG, "Before read"); - if( SUCCEED == (ret = zbx_tcp_recv(&s, &buf)) ) + if( SUCCEED == (ret = zbx_tcp_recv_ext(&s, &buf, ZBX_TCP_READ_UNTIL_CLOSE)) ) { parse_list_of_checks(buf); } diff --git a/src/zabbix_get/zabbix_get.c b/src/zabbix_get/zabbix_get.c index 439684be..1b8f2bb1 100644 --- a/src/zabbix_get/zabbix_get.c +++ b/src/zabbix_get/zabbix_get.c @@ -147,7 +147,7 @@ static int get_value( zbx_snprintf(request, sizeof(request),"%s\n",key); if( SUCCEED == (ret = zbx_tcp_send(&s, request)) ) { - if( SUCCEED == (ret = zbx_tcp_recv(&s, &buf)) ) + if( SUCCEED == (ret = zbx_tcp_recv_ext(&s, &buf, ZBX_TCP_READ_UNTIL_CLOSE)) ) { zbx_rtrim(buf,"\r\n\0"); zbx_snprintf(value, value_max_len, "%s", buf); diff --git a/src/zabbix_server/poller/checks_agent.c b/src/zabbix_server/poller/checks_agent.c index 582b74c4..4ab808fc 100644 --- a/src/zabbix_server/poller/checks_agent.c +++ b/src/zabbix_server/poller/checks_agent.c @@ -69,7 +69,7 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result) { zabbix_log(LOG_LEVEL_DEBUG, "Before read"); - ret = zbx_tcp_recv(&s, &buf); + ret = zbx_tcp_recv_ext(&s, &buf, ZBX_TCP_READ_UNTIL_CLOSE); } } |