mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
Broke some (too long) lines down to multiple lines, made the file fit our coding standards
This commit is contained in:
parent
78201c0146
commit
2442b985bf
@ -232,7 +232,8 @@ lwip_bind(int s, struct sockaddr *name, socklen_t namelen)
|
||||
if (!sock)
|
||||
return -1;
|
||||
|
||||
LWIP_ASSERT("lwip_bind: invalid address", (namelen == sizeof(struct sockaddr_in)) && ((((struct sockaddr_in *)name)->sin_family) == AF_INET));
|
||||
LWIP_ASSERT("lwip_bind: invalid address", (namelen == sizeof(struct sockaddr_in)) &&
|
||||
((((struct sockaddr_in *)name)->sin_family) == AF_INET));
|
||||
|
||||
local_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr;
|
||||
local_port = ((struct sockaddr_in *)name)->sin_port;
|
||||
@ -292,7 +293,8 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
|
||||
if (!sock)
|
||||
return -1;
|
||||
|
||||
LWIP_ASSERT("lwip_connect: invalid address", (namelen == sizeof(struct sockaddr_in)) && ((((struct sockaddr_in *)name)->sin_family) == AF_INET));
|
||||
LWIP_ASSERT("lwip_connect: invalid address", (namelen == sizeof(struct sockaddr_in)) &&
|
||||
((((struct sockaddr_in *)name)->sin_family) == AF_INET));
|
||||
|
||||
if (((struct sockaddr_in *)name)->sin_family == AF_UNSPEC) {
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, AF_UNSPEC)\n", s));
|
||||
@ -468,7 +470,8 @@ lwip_send(int s, const void *data, int size, unsigned int flags)
|
||||
struct lwip_socket *sock;
|
||||
err_t err;
|
||||
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d, data=%p, size=%d, flags=0x%x)\n", s, data, size, flags));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d, data=%p, size=%d, flags=0x%x)\n",
|
||||
s, data, size, flags));
|
||||
|
||||
sock = get_socket(s);
|
||||
if (!sock)
|
||||
@ -511,7 +514,9 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
|
||||
return -1;
|
||||
#endif /* LWIP_TCP */
|
||||
|
||||
LWIP_ASSERT("lwip_sendto: invalid address", (((to==NULL) && (tolen==0)) || ((tolen == sizeof(struct sockaddr_in)) && ((((struct sockaddr_in *)to)->sin_family) == AF_INET))) );
|
||||
LWIP_ASSERT("lwip_sendto: invalid address", (((to==NULL) && (tolen==0)) ||
|
||||
((tolen == sizeof(struct sockaddr_in)) &&
|
||||
((((struct sockaddr_in *)to)->sin_family) == AF_INET))));
|
||||
|
||||
/* initialize a buffer */
|
||||
buf.p = buf.ptr = NULL;
|
||||
@ -527,7 +532,8 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
|
||||
buf.port = 0;
|
||||
}
|
||||
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, size=%d, flags=0x%x to=", s, data, size, flags));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, size=%d, flags=0x%x to=",
|
||||
s, data, size, flags));
|
||||
ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u\n", remote_port));
|
||||
|
||||
@ -556,18 +562,22 @@ lwip_socket(int domain, int type, int protocol)
|
||||
switch (type) {
|
||||
case SOCK_RAW:
|
||||
conn = netconn_new_with_proto_and_callback(NETCONN_RAW, protocol, event_callback);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_RAW, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_RAW, %d) = ",
|
||||
domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
|
||||
break;
|
||||
case SOCK_DGRAM:
|
||||
conn = netconn_new_with_callback(NETCONN_UDP, event_callback);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_DGRAM, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_DGRAM, %d) = ",
|
||||
domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
|
||||
break;
|
||||
case SOCK_STREAM:
|
||||
conn = netconn_new_with_callback(NETCONN_TCP, event_callback);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_STREAM, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_STREAM, %d) = ",
|
||||
domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
|
||||
break;
|
||||
default:
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%d, %d/UNKNOWN, %d) = -1\n", domain, type, protocol));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%d, %d/UNKNOWN, %d) = -1\n",
|
||||
domain, type, protocol));
|
||||
set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
@ -610,25 +620,20 @@ lwip_selscan(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset)
|
||||
|
||||
/* Go through each socket in each list to count number of sockets which
|
||||
currently match */
|
||||
for(i = 0; i < maxfdp1; i++)
|
||||
{
|
||||
if (FD_ISSET(i, readset))
|
||||
{
|
||||
for(i = 0; i < maxfdp1; i++) {
|
||||
if (FD_ISSET(i, readset)) {
|
||||
/* See if netconn of this socket is ready for read */
|
||||
p_sock = get_socket(i);
|
||||
if (p_sock && (p_sock->lastdata || p_sock->rcvevent))
|
||||
{
|
||||
if (p_sock && (p_sock->lastdata || p_sock->rcvevent)) {
|
||||
FD_SET(i, &lreadset);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for reading\n", i));
|
||||
nready++;
|
||||
}
|
||||
}
|
||||
if (FD_ISSET(i, writeset))
|
||||
{
|
||||
if (FD_ISSET(i, writeset)) {
|
||||
/* See if netconn of this socket is ready for write */
|
||||
p_sock = get_socket(i);
|
||||
if (p_sock && p_sock->sendevent)
|
||||
{
|
||||
if (p_sock && p_sock->sendevent) {
|
||||
FD_SET(i, &lwriteset);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for writing\n", i));
|
||||
nready++;
|
||||
@ -653,7 +658,9 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
|
||||
struct lwip_select_cb select_cb;
|
||||
struct lwip_select_cb *p_selcb;
|
||||
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select(%d, %p, %p, %p, tvsec=%ld tvusec=%ld)\n", maxfdp1, (void *)readset, (void *) writeset, (void *) exceptset, timeout ? timeout->tv_sec : -1L, timeout ? timeout->tv_usec : -1L));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select(%d, %p, %p, %p, tvsec=%ld tvusec=%ld)\n",
|
||||
maxfdp1, (void *)readset, (void *) writeset, (void *) exceptset,
|
||||
timeout ? timeout->tv_sec : -1L, timeout ? timeout->tv_usec : -1L));
|
||||
|
||||
select_cb.next = 0;
|
||||
select_cb.readset = readset;
|
||||
@ -682,10 +689,8 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
|
||||
nready = lwip_selscan(maxfdp1, &lreadset, &lwriteset, &lexceptset);
|
||||
|
||||
/* If we don't have any current events, then suspend if we are supposed to */
|
||||
if (!nready)
|
||||
{
|
||||
if (timeout && timeout->tv_sec == 0 && timeout->tv_usec == 0)
|
||||
{
|
||||
if (!nready) {
|
||||
if (timeout && timeout->tv_sec == 0 && timeout->tv_usec == 0) {
|
||||
sys_sem_signal(selectsem);
|
||||
if (readset)
|
||||
FD_ZERO(readset);
|
||||
@ -731,18 +736,18 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
|
||||
if (select_cb_list == &select_cb)
|
||||
select_cb_list = select_cb.next;
|
||||
else
|
||||
for (p_selcb = select_cb_list; p_selcb; p_selcb = p_selcb->next)
|
||||
if (p_selcb->next == &select_cb)
|
||||
{
|
||||
for (p_selcb = select_cb_list; p_selcb; p_selcb = p_selcb->next) {
|
||||
if (p_selcb->next == &select_cb) {
|
||||
p_selcb->next = select_cb.next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sys_sem_signal(selectsem);
|
||||
|
||||
sys_sem_free(select_cb.sem);
|
||||
if (i == 0) /* Timeout */
|
||||
{
|
||||
if (i == 0) {
|
||||
/* Timeout */
|
||||
if (readset)
|
||||
FD_ZERO(readset);
|
||||
if (writeset)
|
||||
@ -771,8 +776,7 @@ lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
|
||||
|
||||
/* See what's set */
|
||||
nready = lwip_selscan(maxfdp1, &lreadset, &lwriteset, &lexceptset);
|
||||
}
|
||||
else
|
||||
} else
|
||||
sys_sem_signal(selectsem);
|
||||
|
||||
if (readset)
|
||||
@ -796,11 +800,9 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
|
||||
struct lwip_select_cb *scb;
|
||||
|
||||
/* Get socket */
|
||||
if (conn)
|
||||
{
|
||||
if (conn) {
|
||||
s = conn->socket;
|
||||
if (s < 0)
|
||||
{
|
||||
if (s < 0) {
|
||||
/* Data comes in right away after an accept, even though
|
||||
* the server task might not have created a new socket yet.
|
||||
* Just count down (or up) if that's the case and we
|
||||
@ -814,14 +816,12 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
|
||||
sock = get_socket(s);
|
||||
if (!sock)
|
||||
return;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return;
|
||||
|
||||
sys_sem_wait(selectsem);
|
||||
/* Set event as required */
|
||||
switch (evt)
|
||||
{
|
||||
switch (evt) {
|
||||
case NETCONN_EVT_RCVPLUS:
|
||||
sock->rcvevent++;
|
||||
break;
|
||||
@ -844,13 +844,10 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
|
||||
multiple times ONLY IF a select was actually waiting. We go through
|
||||
the list the number of waiting select calls + 1. This list is
|
||||
expected to be small. */
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
sys_sem_wait(selectsem);
|
||||
for (scb = select_cb_list; scb; scb = scb->next)
|
||||
{
|
||||
if (scb->sem_signalled == 0)
|
||||
{
|
||||
for (scb = select_cb_list; scb; scb = scb->next) {
|
||||
if (scb->sem_signalled == 0) {
|
||||
/* Test this select call for our socket */
|
||||
if (scb->readset && FD_ISSET(s, scb->readset))
|
||||
if (sock->rcvevent)
|
||||
@ -860,8 +857,7 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (scb)
|
||||
{
|
||||
if (scb) {
|
||||
scb->sem_signalled = 1;
|
||||
sys_sem_signal(selectsem);
|
||||
sys_sem_signal(scb->sem);
|
||||
@ -944,13 +940,13 @@ int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen)
|
||||
|
||||
int lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
|
||||
{
|
||||
int err = 0;
|
||||
int err = ERR_OK;
|
||||
struct lwip_socket *sock = get_socket(s);
|
||||
|
||||
if (!sock)
|
||||
return -1;
|
||||
|
||||
if( NULL == optval || NULL == optlen ) {
|
||||
if ((NULL == optval) || (NULL == optlen)) {
|
||||
sock_set_errno(sock, EFAULT);
|
||||
return -1;
|
||||
}
|
||||
@ -990,9 +986,10 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
||||
break;
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n",
|
||||
s, optname));
|
||||
err = ENOPROTOOPT;
|
||||
} /* switch */
|
||||
} /* switch (optname) */
|
||||
break;
|
||||
|
||||
/* Level: IPPROTO_IP */
|
||||
@ -1009,9 +1006,10 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
||||
break;
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n",
|
||||
s, optname));
|
||||
err = ENOPROTOOPT;
|
||||
} /* switch */
|
||||
} /* switch (optname) */
|
||||
break;
|
||||
|
||||
/* Level: IPPROTO_TCP */
|
||||
@ -1022,7 +1020,8 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
||||
}
|
||||
|
||||
/* If this is no TCP socket, ignore any options. */
|
||||
if ( sock->conn->type != NETCONN_TCP ) return 0;
|
||||
if (sock->conn->type != NETCONN_TCP)
|
||||
return 0;
|
||||
|
||||
switch (optname) {
|
||||
case TCP_NODELAY:
|
||||
@ -1035,19 +1034,21 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
||||
break;
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n",
|
||||
s, optname));
|
||||
err = ENOPROTOOPT;
|
||||
} /* switch */
|
||||
} /* switch (optname */
|
||||
break;
|
||||
|
||||
/* UNDEFINED LEVEL */
|
||||
default:
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n", s, level, optname));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n",
|
||||
s, level, optname));
|
||||
err = ENOPROTOOPT;
|
||||
} /* switch */
|
||||
|
||||
|
||||
if( 0 != err ) {
|
||||
if (err != ERR_OK) {
|
||||
sock_set_errno(sock, err);
|
||||
return -1;
|
||||
}
|
||||
@ -1073,7 +1074,8 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
||||
#endif /* SO_REUSE */
|
||||
/*case SO_USELOOPBACK: UNIMPL */
|
||||
*(int*)optval = sock->conn->pcb.tcp->so_options & optname;
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, optname=0x%x, ..) = %s\n", s, optname, (*(int*)optval?"on":"off")));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, optname=0x%x, ..) = %s\n",
|
||||
s, optname, (*(int*)optval?"on":"off")));
|
||||
break;
|
||||
|
||||
case SO_TYPE:
|
||||
@ -1091,15 +1093,19 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
||||
break;
|
||||
default: /* unrecognized socket type */
|
||||
*(int*)optval = sock->conn->type;
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_TYPE): unrecognized socket type %d\n", s, *(int *)optval));
|
||||
} /* switch */
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_TYPE) = %d\n", s, *(int *)optval));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG,
|
||||
("lwip_getsockopt(%d, SOL_SOCKET, SO_TYPE): unrecognized socket type %d\n",
|
||||
s, *(int *)optval));
|
||||
} /* switch (sock->conn->type) */
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_TYPE) = %d\n",
|
||||
s, *(int *)optval));
|
||||
break;
|
||||
|
||||
case SO_ERROR:
|
||||
*(int *)optval = sock->err;
|
||||
sock->err = 0;
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_ERROR) = %d\n", s, *(int *)optval));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_ERROR) = %d\n",
|
||||
s, *(int *)optval));
|
||||
break;
|
||||
|
||||
#if LWIP_SO_RCVTIMEO
|
||||
@ -1107,7 +1113,7 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
||||
*(int *)optval = sock->conn->recv_timeout;
|
||||
break;
|
||||
#endif /* LWIP_SO_RCVTIMEO */
|
||||
} /* switch */
|
||||
} /* switch (optname) */
|
||||
break;
|
||||
|
||||
/* Level: IPPROTO_IP */
|
||||
@ -1115,13 +1121,15 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
||||
switch (optname) {
|
||||
case IP_TTL:
|
||||
*(int*)optval = sock->conn->pcb.tcp->ttl;
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_TTL) = %d\n", s, *(int *)optval));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_TTL) = %d\n",
|
||||
s, *(int *)optval));
|
||||
break;
|
||||
case IP_TOS:
|
||||
*(int*)optval = sock->conn->pcb.tcp->tos;
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_TOS) = %d\n", s, *(int *)optval));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_TOS) = %d\n",
|
||||
s, *(int *)optval));
|
||||
break;
|
||||
} /* switch */
|
||||
} /* switch (optname) */
|
||||
break;
|
||||
|
||||
/* Level: IPPROTO_TCP */
|
||||
@ -1129,31 +1137,36 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
||||
switch (optname) {
|
||||
case TCP_NODELAY:
|
||||
*(int*)optval = (sock->conn->pcb.tcp->flags & TF_NODELAY);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, TCP_NODELAY) = %s\n", s, (*(int*)optval)?"on":"off") );
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, TCP_NODELAY) = %s\n",
|
||||
s, (*(int*)optval)?"on":"off") );
|
||||
break;
|
||||
case TCP_KEEPALIVE:
|
||||
*(int*)optval = (int)sock->conn->pcb.tcp->keep_idle;
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPALIVE) = %d\n", s, *(int *)optval));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPALIVE) = %d\n",
|
||||
s, *(int *)optval));
|
||||
break;
|
||||
|
||||
#if LWIP_TCP_KEEPALIVE
|
||||
case TCP_KEEPIDLE:
|
||||
*(int*)optval = (int)(sock->conn->pcb.tcp->keep_idle/1000);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPIDLE) = %d\n", s, *(int *)optval));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPIDLE) = %d\n",
|
||||
s, *(int *)optval));
|
||||
break;
|
||||
case TCP_KEEPINTVL:
|
||||
*(int*)optval = (int)(sock->conn->pcb.tcp->keep_intvl/1000);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPINTVL) = %d\n", s, *(int *)optval));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPINTVL) = %d\n",
|
||||
s, *(int *)optval));
|
||||
break;
|
||||
case TCP_KEEPCNT:
|
||||
*(int*)optval = (int)sock->conn->pcb.tcp->keep_cnt;
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPCNT) = %d\n", s, *(int *)optval));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPCNT) = %d\n",
|
||||
s, *(int *)optval));
|
||||
break;
|
||||
#endif /* LWIP_TCP_KEEPALIVE */
|
||||
|
||||
} /* switch */
|
||||
} /* switch (optname) */
|
||||
break;
|
||||
}
|
||||
} /* switch (level) */
|
||||
|
||||
sock_set_errno(sock, err);
|
||||
return err ? -1 : 0;
|
||||
@ -1162,7 +1175,7 @@ int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *opt
|
||||
int lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
|
||||
{
|
||||
struct lwip_socket *sock = get_socket(s);
|
||||
int err = 0;
|
||||
int err = ERR_OK;
|
||||
|
||||
if (!sock)
|
||||
return -1;
|
||||
@ -1203,9 +1216,10 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n",
|
||||
s, optname));
|
||||
err = ENOPROTOOPT;
|
||||
} /* switch */
|
||||
} /* switch (optname) */
|
||||
break;
|
||||
|
||||
/* Level: IPPROTO_IP */
|
||||
@ -1222,24 +1236,22 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
||||
break;
|
||||
#if LWIP_IGMP
|
||||
case IP_MULTICAST_TTL:
|
||||
{
|
||||
/* NOTE, some BSD implementation use "int", some others "char" */
|
||||
if ((optlen != sizeof(char)) && (optlen != sizeof(int)))
|
||||
err = EINVAL;
|
||||
break;
|
||||
}
|
||||
case IP_ADD_MEMBERSHIP:
|
||||
case IP_DROP_MEMBERSHIP:
|
||||
{ if( optlen < sizeof(struct ip_mreq) ) {
|
||||
if (optlen < sizeof(struct ip_mreq)) {
|
||||
err = EINVAL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif /* LWIP_IGMP */
|
||||
default:
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n",
|
||||
s, optname));
|
||||
err = ENOPROTOOPT;
|
||||
} /* switch */
|
||||
} /* switch (optname) */
|
||||
break;
|
||||
|
||||
/* Level: IPPROTO_TCP */
|
||||
@ -1250,7 +1262,8 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
||||
}
|
||||
|
||||
/* If this is no TCP socket, ignore any options. */
|
||||
if ( sock->conn->type != NETCONN_TCP ) return 0;
|
||||
if (sock->conn->type != NETCONN_TCP)
|
||||
return 0;
|
||||
|
||||
switch (optname) {
|
||||
case TCP_NODELAY:
|
||||
@ -1263,19 +1276,21 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
||||
break;
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n",
|
||||
s, optname));
|
||||
err = ENOPROTOOPT;
|
||||
} /* switch */
|
||||
} /* switch (optname) */
|
||||
break;
|
||||
|
||||
/* UNDEFINED LEVEL */
|
||||
default:
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n", s, level, optname));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n",
|
||||
s, level, optname));
|
||||
err = ENOPROTOOPT;
|
||||
} /* switch */
|
||||
} /* switch (level) */
|
||||
|
||||
|
||||
if( 0 != err ) {
|
||||
if (err != ERR_OK) {
|
||||
sock_set_errno(sock, err);
|
||||
return -1;
|
||||
}
|
||||
@ -1305,14 +1320,15 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
||||
} else {
|
||||
sock->conn->pcb.tcp->so_options &= ~optname;
|
||||
}
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, optname=0x%x, ..) -> %s\n", s, optname, (*(int*)optval?"on":"off")));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, optname=0x%x, ..) -> %s\n",
|
||||
s, optname, (*(int*)optval?"on":"off")));
|
||||
break;
|
||||
#if LWIP_SO_RCVTIMEO
|
||||
case SO_RCVTIMEO:
|
||||
sock->conn->recv_timeout = ( *(int*)optval );
|
||||
break;
|
||||
#endif /* LWIP_SO_RCVTIMEO */
|
||||
} /* switch */
|
||||
} /* switch (optname) */
|
||||
break;
|
||||
|
||||
/* Level: IPPROTO_IP */
|
||||
@ -1320,34 +1336,37 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
||||
switch (optname) {
|
||||
case IP_TTL:
|
||||
sock->conn->pcb.tcp->ttl = (u8_t)(*(int*)optval);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TTL, ..) -> %u\n", s, sock->conn->pcb.tcp->ttl));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TTL, ..) -> %u\n",
|
||||
s, sock->conn->pcb.tcp->ttl));
|
||||
break;
|
||||
case IP_TOS:
|
||||
sock->conn->pcb.tcp->tos = (u8_t)(*(int*)optval);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TOS, ..)-> %u\n", s, sock->conn->pcb.tcp->tos));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TOS, ..)-> %u\n",
|
||||
s, sock->conn->pcb.tcp->tos));
|
||||
break;
|
||||
#if LWIP_IGMP
|
||||
case IP_MULTICAST_TTL:
|
||||
{ if (optlen==sizeof(int)) sock->conn->pcb.tcp->ttl = (u8_t)(*(int*) optval);
|
||||
if (optlen==sizeof(u8_t)) sock->conn->pcb.tcp->ttl = (u8_t)(*(u8_t*)optval);
|
||||
if (optlen == sizeof(int))
|
||||
sock->conn->pcb.tcp->ttl = (u8_t)(*(int*) optval);
|
||||
if (optlen == sizeof(u8_t))
|
||||
sock->conn->pcb.tcp->ttl = (u8_t)(*(u8_t*)optval);
|
||||
break;
|
||||
}
|
||||
case IP_ADD_MEMBERSHIP:
|
||||
case IP_DROP_MEMBERSHIP:
|
||||
{ /* If this is a TCP or a RAW socket, ignore these options. */
|
||||
if ((sock->conn->type == NETCONN_TCP) || (sock->conn->type == NETCONN_RAW))
|
||||
{ err = EAFNOSUPPORT;
|
||||
}
|
||||
else
|
||||
{ struct ip_mreq *imr = (struct ip_mreq *)optval;
|
||||
if (netconn_join_leave_group( sock->conn, (struct ip_addr *)&(imr->imr_multiaddr.s_addr), (struct ip_addr *)&(imr->imr_interface.s_addr), ((optname==IP_ADD_MEMBERSHIP)?NETCONN_JOIN:NETCONN_LEAVE)) < 0)
|
||||
{ err = EADDRNOTAVAIL;
|
||||
/* If this is a TCP or a RAW socket, ignore these options. */
|
||||
if ((sock->conn->type == NETCONN_TCP) || (sock->conn->type == NETCONN_RAW)) {
|
||||
err = EAFNOSUPPORT;
|
||||
} else {
|
||||
struct ip_mreq *imr = (struct ip_mreq *)optval;
|
||||
if (netconn_join_leave_group(sock->conn, (struct ip_addr *)&(imr->imr_multiaddr.s_addr),
|
||||
(struct ip_addr *)&(imr->imr_interface.s_addr),
|
||||
((optname==IP_ADD_MEMBERSHIP)?NETCONN_JOIN:NETCONN_LEAVE)) < 0) {
|
||||
err = EADDRNOTAVAIL;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif /* LWIP_IGMP */
|
||||
} /* switch */
|
||||
} /* switch (optname) */
|
||||
break;
|
||||
|
||||
/* Level: IPPROTO_TCP */
|
||||
@ -1359,31 +1378,36 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
|
||||
} else {
|
||||
sock->conn->pcb.tcp->flags &= ~TF_NODELAY;
|
||||
}
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_NODELAY) -> %s\n", s, (*(int *)optval)?"on":"off") );
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_NODELAY) -> %s\n",
|
||||
s, (*(int *)optval)?"on":"off") );
|
||||
break;
|
||||
case TCP_KEEPALIVE:
|
||||
sock->conn->pcb.tcp->keep_idle = (u32_t)(*(int*)optval);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPALIVE) -> %lu\n", s, sock->conn->pcb.tcp->keep_idle));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPALIVE) -> %lu\n",
|
||||
s, sock->conn->pcb.tcp->keep_idle));
|
||||
break;
|
||||
|
||||
#if LWIP_TCP_KEEPALIVE
|
||||
case TCP_KEEPIDLE:
|
||||
sock->conn->pcb.tcp->keep_idle = 1000*(u32_t)(*(int*)optval);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPIDLE) -> %lu\n", s, sock->conn->pcb.tcp->keep_idle));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPIDLE) -> %lu\n",
|
||||
s, sock->conn->pcb.tcp->keep_idle));
|
||||
break;
|
||||
case TCP_KEEPINTVL:
|
||||
sock->conn->pcb.tcp->keep_intvl = 1000*(u32_t)(*(int*)optval);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPINTVL) -> %lu\n", s, sock->conn->pcb.tcp->keep_intvl));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPINTVL) -> %lu\n",
|
||||
s, sock->conn->pcb.tcp->keep_intvl));
|
||||
break;
|
||||
case TCP_KEEPCNT:
|
||||
sock->conn->pcb.tcp->keep_cnt = (u32_t)(*(int*)optval);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPCNT) -> %lu\n", s, sock->conn->pcb.tcp->keep_cnt));
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPCNT) -> %lu\n",
|
||||
s, sock->conn->pcb.tcp->keep_cnt));
|
||||
break;
|
||||
#endif /* LWIP_TCP_KEEPALIVE */
|
||||
|
||||
} /* switch */
|
||||
} /* switch (optname) */
|
||||
break;
|
||||
} /* switch */
|
||||
} /* switch (level) */
|
||||
|
||||
sock_set_errno(sock, err);
|
||||
return err ? -1 : 0;
|
||||
@ -1431,7 +1455,7 @@ int lwip_ioctl(int s, long cmd, void *argp)
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, UNIMPL: 0x%lx, %p)\n", s, cmd, argp));
|
||||
sock_set_errno(sock, ENOSYS); /* not yet implemented */
|
||||
return -1;
|
||||
}
|
||||
} /* switch (cmd) */
|
||||
}
|
||||
|
||||
#endif /* !NO_SYS */
|
||||
|
Loading…
Reference in New Issue
Block a user