version 1.1.2.2, 2013/08/12 23:19:59
|
version 1.1.2.3, 2013/08/12 23:25:35
|
Line 76 ioInitSocket(int role, int type, int proto, const char
|
Line 76 ioInitSocket(int role, int type, int proto, const char
|
s->sock_role = role; |
s->sock_role = role; |
s->sock_type = type; |
s->sock_type = type; |
s->sock_proto = proto; |
s->sock_proto = proto; |
e_gethostbyname(addr, port, &s->sock_addr); | if (!e_gethostbyname(addr, port, &s->sock_addr)) { |
AIT_SET_BUFSIZ(&s->sock_buf, 0, buflen ? buflen : BUFSIZ); | io_SetErr(elwix_GetErrno(), "%s", elwix_GetError()); |
| e_free(s); |
| return NULL; |
| } else |
| AIT_SET_BUFSIZ(&s->sock_buf, 0, buflen ? buflen : BUFSIZ); |
|
|
s->sock_fd = socket(s->sock_addr.sa.sa_family, s->sock_type, s->sock_proto); |
s->sock_fd = socket(s->sock_addr.sa.sa_family, s->sock_type, s->sock_proto); |
if (s->sock_fd == -1) { |
if (s->sock_fd == -1) { |
Line 98 ioInitSocket(int role, int type, int proto, const char
|
Line 102 ioInitSocket(int role, int type, int proto, const char
|
e_free(s); |
e_free(s); |
return NULL; |
return NULL; |
} |
} |
|
if (setsockopt(s->sock_fd, SOL_SOCKET, SO_REUSEADDR, &n, sizeof n) == -1) { |
|
LOGERR; |
|
AIT_FREE_VAL(&s->sock_buf); |
|
e_free(s); |
|
return NULL; |
|
} |
if (bind(s->sock_fd, &s->sock_addr.sa, s->sock_addr.sa.sa_len) == -1) { |
if (bind(s->sock_fd, &s->sock_addr.sa, s->sock_addr.sa.sa_len) == -1) { |
LOGERR; |
LOGERR; |
AIT_FREE_VAL(&s->sock_buf); |
AIT_FREE_VAL(&s->sock_buf); |
Line 105 ioInitSocket(int role, int type, int proto, const char
|
Line 115 ioInitSocket(int role, int type, int proto, const char
|
return NULL; |
return NULL; |
} |
} |
|
|
switch (s->sock_role) { |
|
case IO_SOCK_TYPE_CLIENT: |
|
break; |
|
case IO_SOCK_TYPE_SERVER: |
|
if (setsockopt(s->sock_fd, SOL_SOCKET, SO_REUSEADDR, &n, sizeof n) == -1) { |
|
LOGERR; |
|
AIT_FREE_VAL(&s->sock_buf); |
|
e_free(s); |
|
return NULL; |
|
} |
|
break; |
|
default: |
|
io_SetErr(EINVAL, "Unsupported socket type"); |
|
AIT_FREE_VAL(&s->sock_buf); |
|
e_free(s); |
|
return NULL; |
|
} |
|
|
|
return s; |
return s; |
} |
} |
|
|
Line 163 ioUpSocket(sock_t * __restrict s, void *arg)
|
Line 155 ioUpSocket(sock_t * __restrict s, void *arg)
|
return -1; |
return -1; |
|
|
switch (s->sock_role) { |
switch (s->sock_role) { |
case IO_SOCK_TYPE_CLIENT: | case IO_SOCK_ROLE_CLIENT: |
memcpy(&s->sock_peer, peer, sizeof s->sock_peer); |
memcpy(&s->sock_peer, peer, sizeof s->sock_peer); |
|
|
if (connect(s->sock_fd, &s->sock_peer.sa, |
if (connect(s->sock_fd, &s->sock_peer.sa, |
Line 172 ioUpSocket(sock_t * __restrict s, void *arg)
|
Line 164 ioUpSocket(sock_t * __restrict s, void *arg)
|
return -1; |
return -1; |
} |
} |
break; |
break; |
case IO_SOCK_TYPE_SERVER: | case IO_SOCK_ROLE_SERVER: |
s->sock_backq = backlog; | if (s->sock_type == SOCK_STREAM) { |
| s->sock_backq = backlog; |
|
|
if (listen(s->sock_fd, s->sock_backq) == -1) { | if (listen(s->sock_fd, s->sock_backq) == -1) { |
LOGERR; | LOGERR; |
return -1; | return -1; |
| } |
} |
} |
break; |
break; |
default: |
default: |