Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixed problem on OS/X; SOCK_CLOEXEC raises EPROTONOSUPPORT instead
of EINVAL.
  • Loading branch information
waTeim committed Feb 18, 2014
commit 4d20b56236208b837e59b1f589ad30d4f22068d3
14 changes: 12 additions & 2 deletions src/webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ int create_socket (int domain, int type, int protocol)
/* use SOCK_STREAM rather than ai_socktype: some getaddrinfo
* implementations do not set ai_socktype, e.g. RHL6.2. */
fd = socket(domain, ctype, protocol);
if ( (-1 == fd) && (EINVAL == errno) && (0 != sock_cloexec) )
if ( (fd == -1) && (errno == EINVAL || errno == EPROTONOSUPPORT) && (sock_cloexec != 0) )
{
sock_cloexec = 0;
fd = socket(domain, type, protocol);
Expand Down Expand Up @@ -512,6 +512,12 @@ bool webserver::start(bool blocking)
else
bind_socket = create_socket (PF_INET, SOCK_STREAM, 0);

if(bind_socket == -1)
{
perror("Unable to create socket");
abort();
}

setsockopt (bind_socket,
SOL_SOCKET,
SO_REUSEADDR,
Expand All @@ -528,7 +534,11 @@ bool webserver::start(bool blocking)
#endif
#endif
}
bind(bind_socket, servaddr, addrlen);
if(bind(bind_socket, servaddr, addrlen) == -1)
{
perror("Unable to bind specified server address");
abort();
}
}
int flags = fcntl (bind_socket, F_GETFL);
flags |= O_NONBLOCK;
Expand Down