|
|
|
|
@ -33,27 +33,6 @@ void set_prefix(char* prefix) {
|
|
|
|
|
graphite_prefix = prefix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a file descriptor to blocking or non-blocking mode.
|
|
|
|
|
*
|
|
|
|
|
* @param fd The file descriptor
|
|
|
|
|
* @param blocking 0:non-blocking mode, 1:blocking mode
|
|
|
|
|
*
|
|
|
|
|
* @return 1:success, 0:failure.
|
|
|
|
|
**/
|
|
|
|
|
int fd_set_blocking(int fd, int blocking) {
|
|
|
|
|
/* Save the current flags */
|
|
|
|
|
int flags = fcntl(fd, F_GETFL, 0);
|
|
|
|
|
if (flags == -1)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (blocking)
|
|
|
|
|
flags &= ~O_NONBLOCK;
|
|
|
|
|
else
|
|
|
|
|
flags |= O_NONBLOCK;
|
|
|
|
|
return fcntl(fd, F_SETFL, flags) != -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int connect_to_graphite_server(u_int32_t ipaddress, int port) {
|
|
|
|
|
|
|
|
|
|
if (graphite_sock>0)
|
|
|
|
|
@ -85,11 +64,7 @@ int connect_to_graphite_server(u_int32_t ipaddress, int port) {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rc = fd_set_blocking(graphite_sock,0);
|
|
|
|
|
if (!rc) {
|
|
|
|
|
ilog(LOG_ERROR,"Could not set the socket to nonblocking.");
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
nonblock(graphite_sock);
|
|
|
|
|
|
|
|
|
|
struct in_addr ip;
|
|
|
|
|
ip.s_addr = graphite_ipaddress;
|
|
|
|
|
|