Browse Source

Provide a helper function for turning a socket into a url and port

master
Con Kolivas 10 years ago
parent
commit
be87144fe1
  1. 17
      src/libckpool.c
  2. 2
      src/libckpool.h

17
src/libckpool.c

@ -451,6 +451,23 @@ bool addrinfo_from_url(const char *url, const char *port, struct addrinfo *addri
return true;
}
/* Convert a socket into a url and port. URL should be a string of
* INET6_ADDRSTRLEN size, port at least a string of 6 bytes */
bool url_from_socket(const int sockd, char *url, char *port)
{
socklen_t addrlen = sizeof(struct sockaddr);
struct sockaddr addr;
if (sockd < 1)
return false;
if (getsockname(sockd, &addr, &addrlen))
return false;
if (!url_from_sockaddr(&addr, url, port))
return false;
return true;
}
void keep_sockalive(int fd)
{
const int tcp_one = 1;

2
src/libckpool.h

@ -425,6 +425,8 @@ static inline bool sock_timeout(void)
bool extract_sockaddr(char *url, char **sockaddr_url, char **sockaddr_port);
bool url_from_sockaddr(const struct sockaddr *addr, char *url, char *port);
bool addrinfo_from_url(const char *url, const char *port, struct addrinfo *addrinfo);
bool url_from_socket(const int sockd, char *url, char *port);
void keep_sockalive(int fd);
void nolinger_socket(int fd);
void noblock_socket(int fd);

Loading…
Cancel
Save