Commit fd8a6ae7 authored by Geoff Garside's avatar Geoff Garside Committed by antirez
Browse files

Add anetTcp6Server() function.

Refactor the common code from anetTcpServer into internal function which
can be used by both anetTcpServer and anetTcp6Server.
parent f6382369
......@@ -372,7 +372,7 @@ static int anetV6Only(char *err, int s) {
return ANET_OK;
}
int anetTcpServer(char *err, int port, char *bindaddr)
static int _anetTcpServer(char *err, int port, char *bindaddr, int af)
{
int s, rv;
char _port[6]; /* strlen("65535") */
......@@ -380,7 +380,7 @@ int anetTcpServer(char *err, int port, char *bindaddr)
snprintf(_port,6,"%d",port);
memset(&hints,0,sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_family = af;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE; /* No effect if bindaddr != NULL */
......@@ -392,6 +392,9 @@ int anetTcpServer(char *err, int port, char *bindaddr)
if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == -1)
continue;
if (AF_INET6 == af && anetV6Only(err,s) == ANET_ERR)
goto error; /* could continue here? */
if (anetListen(err,s,p->ai_addr,p->ai_addrlen) == ANET_ERR)
goto error; /* could continue here? */
goto end;
......@@ -408,6 +411,16 @@ end:
return s;
}
int anetTcpServer(char *err, int port, char *bindaddr)
{
return _anetTcpServer(err, port, bindaddr, AF_INET);
}
int anetTcp6Server(char *err, int port, char *bindaddr)
{
return _anetTcpServer(err, port, bindaddr, AF_INET6);
}
int anetUnixServer(char *err, char *path, mode_t perm)
{
int s;
......
......@@ -46,6 +46,7 @@ int anetUnixNonBlockConnect(char *err, char *path);
int anetRead(int fd, char *buf, int count);
int anetResolve(char *err, char *host, char *ipbuf, size_t ipbuf_len);
int anetTcpServer(char *err, int port, char *bindaddr);
int anetTcp6Server(char *err, int port, char *bindaddr);
int anetUnixServer(char *err, char *path, mode_t perm);
int anetTcpAccept(char *err, int serversock, char *ip, size_t ip_len, int *port);
int anetUnixAccept(char *err, int serversock);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment