Ejemplo n.º 1
0
static int anetListen(char *err, int s, struct sockaddr *sa, socklen_t len, int backlog) {
    if (bind(s,sa,len) == -1) {
        anetSetError(err, "bind: %s", strerror(errno));
        close(s);
        return ANET_ERR;
    }

#ifdef WIN32_IOCP
    if (aeWinListen(s, backlog) == SOCKET_ERROR) {
#else
    if (listen(s, backlog) == -1) {
#endif
        anetSetError(err, "listen: %s", strerror(errno));
        close(s);
        return ANET_ERR;
    }
    return ANET_OK;
}

static int anetV6Only(char *err, int s) {
    int yes = 1;
    if (setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,&yes,sizeof(yes)) == -1) {
        anetSetError(err, "setsockopt: %s", strerror(errno));
        close(s);
        return ANET_ERR;
    }
    return ANET_OK;
}
Ejemplo n.º 2
0
static int anetListen(char *err, int s, struct sockaddr *sa, socklen_t len) {
    int r = bind((SOCKET)s,sa,len);
    if (r == SOCKET_ERROR) {
        errno = WSAGetLastError();
        anetSetError(err, "bind error: %d\n", errno);
        closesocket((SOCKET)s);
        return ANET_ERR;
    }
    if (aeWinListen((SOCKET)s, 511) == SOCKET_ERROR) { /* the magic 511 constant is from nginx */
        errno = WSAGetLastError();
        anetSetError(err, "listen error: %d\n", errno);
        closesocket((SOCKET)s);
        return ANET_ERR;
    }
    return ANET_OK;
}