fixed arguments of socket functions to match the standard; converted size argument of netconn_write to 'size_t' for that; fixed some warnings

This commit is contained in:
goldsimon 2009-02-16 19:33:51 +00:00
parent d976c8e85f
commit 14cb4eb735
8 changed files with 61 additions and 49 deletions

View File

@ -68,6 +68,10 @@ HISTORY
++ Bugfixes: ++ Bugfixes:
2009-02-16 Simon Goldschmidt
* sockets.h/.c, api_*.h/.c: fixed arguments of socket functions to match the standard;
converted size argument of netconn_write to 'size_t'
2009-02-16 Simon Goldschmidt 2009-02-16 Simon Goldschmidt
* tcp.h, tcp.c: fixed bug #24440: TCP connection close problem on 64-bit host * tcp.h, tcp.c: fixed bug #24440: TCP connection close problem on 64-bit host
by moving accept callback function pointer to TCP_PCB_COMMON by moving accept callback function pointer to TCP_PCB_COMMON

View File

@ -459,7 +459,7 @@ netconn_send(struct netconn *conn, struct netbuf *buf)
* @return ERR_OK if data was sent, any other err_t on error * @return ERR_OK if data was sent, any other err_t on error
*/ */
err_t err_t
netconn_write(struct netconn *conn, const void *dataptr, int size, u8_t apiflags) netconn_write(struct netconn *conn, const void *dataptr, size_t size, u8_t apiflags)
{ {
struct api_msg msg; struct api_msg msg;

View File

@ -948,17 +948,19 @@ do_writemore(struct netconn *conn)
void *dataptr; void *dataptr;
u16_t len, available; u16_t len, available;
u8_t write_finished = 0; u8_t write_finished = 0;
size_t diff;
LWIP_ASSERT("conn->state == NETCONN_WRITE", (conn->state == NETCONN_WRITE)); LWIP_ASSERT("conn->state == NETCONN_WRITE", (conn->state == NETCONN_WRITE));
dataptr = (u8_t*)conn->write_msg->msg.w.dataptr + conn->write_offset; dataptr = (u8_t*)conn->write_msg->msg.w.dataptr + conn->write_offset;
if (conn->write_msg->msg.w.len - conn->write_offset > 0xffff) { /* max_u16_t */ diff = conn->write_msg->msg.w.len - conn->write_offset;
if (diff > 0xffffUL) { /* max_u16_t */
len = 0xffff; len = 0xffff;
#if LWIP_TCPIP_CORE_LOCKING #if LWIP_TCPIP_CORE_LOCKING
conn->write_delayed = 1; conn->write_delayed = 1;
#endif #endif
} else { } else {
len = conn->write_msg->msg.w.len - conn->write_offset; len = (u16_t)diff;
} }
available = tcp_sndbuf(conn->pcb.tcp); available = tcp_sndbuf(conn->pcb.tcp);
if (available < len) { if (available < len) {
@ -1035,6 +1037,8 @@ do_write(struct api_msg_msg *msg)
#if LWIP_TCP #if LWIP_TCP
msg->conn->state = NETCONN_WRITE; msg->conn->state = NETCONN_WRITE;
/* set all the variables used by do_writemore */ /* set all the variables used by do_writemore */
LWIP_ASSERT("already writing", msg->conn->write_msg == NULL &&
msg->conn->write_offset == 0);
msg->conn->write_msg = msg; msg->conn->write_msg = msg;
msg->conn->write_offset = 0; msg->conn->write_offset = 0;
#if LWIP_TCPIP_CORE_LOCKING #if LWIP_TCPIP_CORE_LOCKING

View File

@ -326,7 +326,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
} }
int int
lwip_bind(int s, struct sockaddr *name, socklen_t namelen) lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
{ {
struct lwip_socket *sock; struct lwip_socket *sock;
struct ip_addr local_addr; struct ip_addr local_addr;
@ -338,11 +338,11 @@ lwip_bind(int s, struct sockaddr *name, socklen_t namelen)
return -1; return -1;
LWIP_ERROR("lwip_bind: invalid address", ((namelen == sizeof(struct sockaddr_in)) && LWIP_ERROR("lwip_bind: invalid address", ((namelen == sizeof(struct sockaddr_in)) &&
((((struct sockaddr_in *)name)->sin_family) == AF_INET)), ((((const struct sockaddr_in *)name)->sin_family) == AF_INET)),
sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;); sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;);
local_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr; local_addr.addr = ((const struct sockaddr_in *)name)->sin_addr.s_addr;
local_port = ((struct sockaddr_in *)name)->sin_port; local_port = ((const struct sockaddr_in *)name)->sin_port;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d, addr=", s)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d, addr=", s));
ip_addr_debug_print(SOCKETS_DEBUG, &local_addr); ip_addr_debug_print(SOCKETS_DEBUG, &local_addr);
@ -398,18 +398,18 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
return -1; return -1;
LWIP_ERROR("lwip_connect: invalid address", ((namelen == sizeof(struct sockaddr_in)) && LWIP_ERROR("lwip_connect: invalid address", ((namelen == sizeof(struct sockaddr_in)) &&
((((struct sockaddr_in *)name)->sin_family) == AF_INET)), ((((const struct sockaddr_in *)name)->sin_family) == AF_INET)),
sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;); sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;);
if (((struct sockaddr_in *)name)->sin_family == AF_UNSPEC) { if (((const struct sockaddr_in *)name)->sin_family == AF_UNSPEC) {
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, AF_UNSPEC)\n", s)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, AF_UNSPEC)\n", s));
err = netconn_disconnect(sock->conn); err = netconn_disconnect(sock->conn);
} else { } else {
struct ip_addr remote_addr; struct ip_addr remote_addr;
u16_t remote_port; u16_t remote_port;
remote_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr; remote_addr.addr = ((const struct sockaddr_in *)name)->sin_addr.s_addr;
remote_port = ((struct sockaddr_in *)name)->sin_port; remote_port = ((const struct sockaddr_in *)name)->sin_port;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, addr=", s)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, addr=", s));
ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr); ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr);
@ -470,7 +470,7 @@ lwip_listen(int s, int backlog)
} }
int int
lwip_recvfrom(int s, void *mem, int len, unsigned int flags, lwip_recvfrom(int s, void *mem, size_t len, int flags,
struct sockaddr *from, socklen_t *fromlen) struct sockaddr *from, socklen_t *fromlen)
{ {
struct lwip_socket *sock; struct lwip_socket *sock;
@ -519,7 +519,7 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
if (len > buflen) { if (len > buflen) {
copylen = buflen; copylen = buflen;
} else { } else {
copylen = len; copylen = (u16_t)len;
} }
/* copy the contents of the received buffer into /* copy the contents of the received buffer into
@ -529,6 +529,7 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
off += copylen; off += copylen;
if (netconn_type(sock->conn) == NETCONN_TCP) { if (netconn_type(sock->conn) == NETCONN_TCP) {
LWIP_ASSERT("invalid copylen, len would underflow", len >= copylen);
len -= copylen; len -= copylen;
if ( (len <= 0) || (buf->p->flags & PBUF_FLAG_PUSH) || !sock->rcvevent || ((flags & MSG_PEEK)!=0)) { if ( (len <= 0) || (buf->p->flags & PBUF_FLAG_PUSH) || !sock->rcvevent || ((flags & MSG_PEEK)!=0)) {
done = 1; done = 1;
@ -607,19 +608,19 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
} }
int int
lwip_read(int s, void *mem, int len) lwip_read(int s, void *mem, size_t len)
{ {
return lwip_recvfrom(s, mem, len, 0, NULL, NULL); return lwip_recvfrom(s, mem, len, 0, NULL, NULL);
} }
int int
lwip_recv(int s, void *mem, int len, unsigned int flags) lwip_recv(int s, void *mem, size_t len, int flags)
{ {
return lwip_recvfrom(s, mem, len, flags, NULL, NULL); return lwip_recvfrom(s, mem, len, flags, NULL, NULL);
} }
int int
lwip_send(int s, const void *data, int size, unsigned int flags) lwip_send(int s, const void *data, size_t size, int flags)
{ {
struct lwip_socket *sock; struct lwip_socket *sock;
err_t err; err_t err;
@ -631,7 +632,7 @@ lwip_send(int s, const void *data, int size, unsigned int flags)
if (!sock) if (!sock)
return -1; return -1;
if (sock->conn->type!=NETCONN_TCP) { if (sock->conn->type != NETCONN_TCP) {
#if (LWIP_UDP || LWIP_RAW) #if (LWIP_UDP || LWIP_RAW)
return lwip_sendto(s, data, size, flags, NULL, 0); return lwip_sendto(s, data, size, flags, NULL, 0);
#else #else
@ -644,16 +645,17 @@ lwip_send(int s, const void *data, int size, unsigned int flags)
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) err=%d size=%d\n", s, err, size)); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) err=%d size=%d\n", s, err, size));
sock_set_errno(sock, err_to_errno(err)); sock_set_errno(sock, err_to_errno(err));
return (err==ERR_OK?size:-1); return (err == ERR_OK ? (int)size : -1);
} }
int int
lwip_sendto(int s, const void *data, int size, unsigned int flags, lwip_sendto(int s, const void *data, size_t size, int flags,
struct sockaddr *to, socklen_t tolen) const struct sockaddr *to, socklen_t tolen)
{ {
struct lwip_socket *sock; struct lwip_socket *sock;
struct ip_addr remote_addr; struct ip_addr remote_addr;
int err; int err;
u16_t short_size;
#if !LWIP_TCPIP_CORE_LOCKING #if !LWIP_TCPIP_CORE_LOCKING
struct netbuf buf; struct netbuf buf;
u16_t remote_port; u16_t remote_port;
@ -663,7 +665,7 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
if (!sock) if (!sock)
return -1; return -1;
if (sock->conn->type==NETCONN_TCP) { if (sock->conn->type == NETCONN_TCP) {
#if LWIP_TCP #if LWIP_TCP
return lwip_send(s, data, size, flags); return lwip_send(s, data, size, flags);
#else #else
@ -672,11 +674,11 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
#endif /* LWIP_TCP */ #endif /* LWIP_TCP */
} }
LWIP_ASSERT("lwip_sendto: size must fit in u16_t", LWIP_ASSERT("lwip_sendto: size must fit in u16_t", size <= 0xffff);
((size >= 0) && (size <= 0xffff))); short_size = (u16_t)size;
LWIP_ERROR("lwip_sendto: invalid address", (((to == NULL) && (tolen == 0)) || LWIP_ERROR("lwip_sendto: invalid address", (((to == NULL) && (tolen == 0)) ||
((tolen == sizeof(struct sockaddr_in)) && ((tolen == sizeof(struct sockaddr_in)) &&
((((struct sockaddr_in *)to)->sin_family) == AF_INET))), ((((const struct sockaddr_in *)to)->sin_family) == AF_INET))),
sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;); sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;);
#if LWIP_TCPIP_CORE_LOCKING #if LWIP_TCPIP_CORE_LOCKING
@ -688,15 +690,15 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
err = ERR_MEM; err = ERR_MEM;
} else { } else {
p->payload = (void*)data; p->payload = (void*)data;
p->len = p->tot_len = size; p->len = p->tot_len = short_size;
remote_addr.addr = ((struct sockaddr_in *)to)->sin_addr.s_addr; remote_addr.addr = ((const struct sockaddr_in *)to)->sin_addr.s_addr;
LOCK_TCPIP_CORE(); LOCK_TCPIP_CORE();
if (sock->conn->type==NETCONN_RAW) { if (sock->conn->type==NETCONN_RAW) {
err = sock->conn->err = raw_sendto(sock->conn->pcb.raw, p, &remote_addr); err = sock->conn->err = raw_sendto(sock->conn->pcb.raw, p, &remote_addr);
} else { } else {
err = sock->conn->err = udp_sendto(sock->conn->pcb.udp, p, &remote_addr, ntohs(((struct sockaddr_in *)to)->sin_port)); err = sock->conn->err = udp_sendto(sock->conn->pcb.udp, p, &remote_addr, ntohs(((const struct sockaddr_in *)to)->sin_port));
} }
UNLOCK_TCPIP_CORE(); UNLOCK_TCPIP_CORE();
@ -707,8 +709,8 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
/* initialize a buffer */ /* initialize a buffer */
buf.p = buf.ptr = NULL; buf.p = buf.ptr = NULL;
if (to) { if (to) {
remote_addr.addr = ((struct sockaddr_in *)to)->sin_addr.s_addr; remote_addr.addr = ((const struct sockaddr_in *)to)->sin_addr.s_addr;
remote_port = ntohs(((struct sockaddr_in *)to)->sin_port); remote_port = ntohs(((const struct sockaddr_in *)to)->sin_port);
buf.addr = &remote_addr; buf.addr = &remote_addr;
buf.port = remote_port; buf.port = remote_port;
} else { } else {
@ -718,13 +720,13 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
buf.port = 0; buf.port = 0;
} }
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, size=%d, flags=0x%x to=", LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, short_size=%d, flags=0x%x to=",
s, data, size, flags)); s, data, short_size, flags));
ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr); ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr);
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u\n", remote_port)); LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u\n", remote_port));
/* make the buffer point to the data that should be sent */ /* make the buffer point to the data that should be sent */
if ((err = netbuf_ref(&buf, data, size)) == ERR_OK) { if ((err = netbuf_ref(&buf, data, short_size)) == ERR_OK) {
/* send the data */ /* send the data */
err = netconn_send(sock->conn, &buf); err = netconn_send(sock->conn, &buf);
} }
@ -735,7 +737,7 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
} }
#endif /* LWIP_TCPIP_CORE_LOCKING */ #endif /* LWIP_TCPIP_CORE_LOCKING */
sock_set_errno(sock, err_to_errno(err)); sock_set_errno(sock, err_to_errno(err));
return (err==ERR_OK?size:-1); return (err == ERR_OK ? short_size : -1);
} }
int int
@ -791,7 +793,7 @@ lwip_socket(int domain, int type, int protocol)
} }
int int
lwip_write(int s, const void *data, int size) lwip_write(int s, const void *data, size_t size)
{ {
return lwip_send(s, data, size, 0); return lwip_send(s, data, size, 0);
} }

View File

@ -2205,10 +2205,10 @@ system_get_value(struct obj_def *od, u16_t len, void *value)
switch (id) switch (id)
{ {
case 1: /* sysDescr */ case 1: /* sysDescr */
ocstrncpy(value,sysdescr_ptr,len); ocstrncpy(value,sysdescr_ptr, len);
break; break;
case 2: /* sysObjectID */ case 2: /* sysObjectID */
objectidncpy((s32_t*)value,(s32_t*)sysobjid.id,len / sizeof(s32_t)); objectidncpy((s32_t*)value, (s32_t*)sysobjid.id, (u8_t)(len / sizeof(s32_t)));
break; break;
case 3: /* sysUpTime */ case 3: /* sysUpTime */
{ {
@ -2606,7 +2606,7 @@ ifentry_get_value(struct obj_def *od, u16_t len, void *value)
} }
break; break;
case 22: /* ifSpecific */ case 22: /* ifSpecific */
objectidncpy((s32_t*)value,(s32_t*)ifspecific.id,len / sizeof(s32_t)); objectidncpy((s32_t*)value, (s32_t*)ifspecific.id, (u8_t)(len / sizeof(s32_t)));
break; break;
}; };
} }
@ -3342,7 +3342,7 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
} }
break; break;
case 13: /* ipRouteInfo */ case 13: /* ipRouteInfo */
objectidncpy((s32_t*)value,(s32_t*)iprouteinfo.id,len / sizeof(s32_t)); objectidncpy((s32_t*)value, (s32_t*)iprouteinfo.id, (u8_t)(len / sizeof(s32_t)));
break; break;
} }
} }

View File

@ -141,9 +141,11 @@ struct netconn {
/** TCP: when data passed to netconn_write doesn't fit into the send buffer, /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
this temporarily stores the message. */ this temporarily stores the message. */
struct api_msg_msg *write_msg; struct api_msg_msg *write_msg;
#if LWIP_TCP
/** TCP: when data passed to netconn_write doesn't fit into the send buffer, /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
this temporarily stores how much is already sent. */ this temporarily stores how much is already sent. */
int write_offset; size_t write_offset;
#endif /* LWIP_TCP */
#if LWIP_TCPIP_CORE_LOCKING #if LWIP_TCPIP_CORE_LOCKING
/** TCP: when data passed to netconn_write doesn't fit into the send buffer, /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
this temporarily stores whether to wake up the original application task this temporarily stores whether to wake up the original application task
@ -191,7 +193,7 @@ err_t netconn_sendto (struct netconn *conn,
err_t netconn_send (struct netconn *conn, err_t netconn_send (struct netconn *conn,
struct netbuf *buf); struct netbuf *buf);
err_t netconn_write (struct netconn *conn, err_t netconn_write (struct netconn *conn,
const void *dataptr, int size, const void *dataptr, size_t size,
u8_t apiflags); u8_t apiflags);
err_t netconn_close (struct netconn *conn); err_t netconn_close (struct netconn *conn);

View File

@ -78,7 +78,7 @@ struct api_msg_msg {
/** used for do_write */ /** used for do_write */
struct { struct {
const void *dataptr; const void *dataptr;
int len; size_t len;
u8_t apiflags; u8_t apiflags;
} w; } w;
/** used ofr do_recv */ /** used ofr do_recv */

View File

@ -297,7 +297,7 @@ struct timeval {
void lwip_socket_init(void); void lwip_socket_init(void);
int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
int lwip_bind(int s, struct sockaddr *name, socklen_t namelen); int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen);
int lwip_shutdown(int s, int how); int lwip_shutdown(int s, int how);
int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen); int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen);
int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen); int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen);
@ -306,15 +306,15 @@ int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_
int lwip_close(int s); int lwip_close(int s);
int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen);
int lwip_listen(int s, int backlog); int lwip_listen(int s, int backlog);
int lwip_recv(int s, void *mem, int len, unsigned int flags); int lwip_recv(int s, void *mem, size_t len, int flags);
int lwip_read(int s, void *mem, int len); int lwip_read(int s, void *mem, size_t len);
int lwip_recvfrom(int s, void *mem, int len, unsigned int flags, int lwip_recvfrom(int s, void *mem, size_t len, int flags,
struct sockaddr *from, socklen_t *fromlen); struct sockaddr *from, socklen_t *fromlen);
int lwip_send(int s, const void *dataptr, int size, unsigned int flags); int lwip_send(int s, const void *dataptr, size_t size, int flags);
int lwip_sendto(int s, const void *dataptr, int size, unsigned int flags, int lwip_sendto(int s, const void *dataptr, size_t size, int flags,
struct sockaddr *to, socklen_t tolen); const struct sockaddr *to, socklen_t tolen);
int lwip_socket(int domain, int type, int protocol); int lwip_socket(int domain, int type, int protocol);
int lwip_write(int s, const void *dataptr, int size); int lwip_write(int s, const void *dataptr, size_t size);
int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
struct timeval *timeout); struct timeval *timeout);
int lwip_ioctl(int s, long cmd, void *argp); int lwip_ioctl(int s, long cmd, void *argp);