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:
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
* 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

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
*/
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;

View File

@ -948,17 +948,19 @@ do_writemore(struct netconn *conn)
void *dataptr;
u16_t len, available;
u8_t write_finished = 0;
size_t diff;
LWIP_ASSERT("conn->state == NETCONN_WRITE", (conn->state == NETCONN_WRITE));
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;
#if LWIP_TCPIP_CORE_LOCKING
conn->write_delayed = 1;
#endif
} else {
len = conn->write_msg->msg.w.len - conn->write_offset;
len = (u16_t)diff;
}
available = tcp_sndbuf(conn->pcb.tcp);
if (available < len) {
@ -1035,6 +1037,8 @@ do_write(struct api_msg_msg *msg)
#if LWIP_TCP
msg->conn->state = NETCONN_WRITE;
/* 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_offset = 0;
#if LWIP_TCPIP_CORE_LOCKING

View File

@ -326,7 +326,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
}
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 ip_addr local_addr;
@ -338,11 +338,11 @@ lwip_bind(int s, struct sockaddr *name, socklen_t namelen)
return -1;
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;);
local_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr;
local_port = ((struct sockaddr_in *)name)->sin_port;
local_addr.addr = ((const struct sockaddr_in *)name)->sin_addr.s_addr;
local_port = ((const struct sockaddr_in *)name)->sin_port;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d, addr=", s));
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;
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;);
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));
err = netconn_disconnect(sock->conn);
} else {
struct ip_addr remote_addr;
u16_t remote_port;
remote_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr;
remote_port = ((struct sockaddr_in *)name)->sin_port;
remote_addr.addr = ((const struct sockaddr_in *)name)->sin_addr.s_addr;
remote_port = ((const struct sockaddr_in *)name)->sin_port;
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, addr=", s));
ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr);
@ -470,7 +470,7 @@ lwip_listen(int s, int backlog)
}
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 lwip_socket *sock;
@ -519,7 +519,7 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
if (len > buflen) {
copylen = buflen;
} else {
copylen = len;
copylen = (u16_t)len;
}
/* 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;
if (netconn_type(sock->conn) == NETCONN_TCP) {
LWIP_ASSERT("invalid copylen, len would underflow", len >= copylen);
len -= copylen;
if ( (len <= 0) || (buf->p->flags & PBUF_FLAG_PUSH) || !sock->rcvevent || ((flags & MSG_PEEK)!=0)) {
done = 1;
@ -607,19 +608,19 @@ lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
}
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);
}
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);
}
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;
err_t err;
@ -631,7 +632,7 @@ lwip_send(int s, const void *data, int size, unsigned int flags)
if (!sock)
return -1;
if (sock->conn->type!=NETCONN_TCP) {
if (sock->conn->type != NETCONN_TCP) {
#if (LWIP_UDP || LWIP_RAW)
return lwip_sendto(s, data, size, flags, NULL, 0);
#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));
sock_set_errno(sock, err_to_errno(err));
return (err==ERR_OK?size:-1);
return (err == ERR_OK ? (int)size : -1);
}
int
lwip_sendto(int s, const void *data, int size, unsigned int flags,
struct sockaddr *to, socklen_t tolen)
lwip_sendto(int s, const void *data, size_t size, int flags,
const struct sockaddr *to, socklen_t tolen)
{
struct lwip_socket *sock;
struct ip_addr remote_addr;
int err;
u16_t short_size;
#if !LWIP_TCPIP_CORE_LOCKING
struct netbuf buf;
u16_t remote_port;
@ -663,7 +665,7 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
if (!sock)
return -1;
if (sock->conn->type==NETCONN_TCP) {
if (sock->conn->type == NETCONN_TCP) {
#if LWIP_TCP
return lwip_send(s, data, size, flags);
#else
@ -672,11 +674,11 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
#endif /* LWIP_TCP */
}
LWIP_ASSERT("lwip_sendto: size must fit in u16_t",
((size >= 0) && (size <= 0xffff)));
LWIP_ASSERT("lwip_sendto: size must fit in u16_t", size <= 0xffff);
short_size = (u16_t)size;
LWIP_ERROR("lwip_sendto: invalid address", (((to == NULL) && (tolen == 0)) ||
((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;);
#if LWIP_TCPIP_CORE_LOCKING
@ -688,15 +690,15 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
err = ERR_MEM;
} else {
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();
if (sock->conn->type==NETCONN_RAW) {
err = sock->conn->err = raw_sendto(sock->conn->pcb.raw, p, &remote_addr);
} 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();
@ -707,8 +709,8 @@ lwip_sendto(int s, const void *data, int size, unsigned int flags,
/* initialize a buffer */
buf.p = buf.ptr = NULL;
if (to) {
remote_addr.addr = ((struct sockaddr_in *)to)->sin_addr.s_addr;
remote_port = ntohs(((struct sockaddr_in *)to)->sin_port);
remote_addr.addr = ((const struct sockaddr_in *)to)->sin_addr.s_addr;
remote_port = ntohs(((const struct sockaddr_in *)to)->sin_port);
buf.addr = &remote_addr;
buf.port = remote_port;
} else {
@ -718,13 +720,13 @@ 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, short_size=%d, flags=0x%x to=",
s, data, short_size, flags));
ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr);
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u\n", remote_port));
/* 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 */
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 */
sock_set_errno(sock, err_to_errno(err));
return (err==ERR_OK?size:-1);
return (err == ERR_OK ? short_size : -1);
}
int
@ -791,7 +793,7 @@ lwip_socket(int domain, int type, int protocol)
}
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);
}

View File

@ -2205,10 +2205,10 @@ system_get_value(struct obj_def *od, u16_t len, void *value)
switch (id)
{
case 1: /* sysDescr */
ocstrncpy(value,sysdescr_ptr,len);
ocstrncpy(value,sysdescr_ptr, len);
break;
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;
case 3: /* sysUpTime */
{
@ -2606,7 +2606,7 @@ ifentry_get_value(struct obj_def *od, u16_t len, void *value)
}
break;
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;
};
}
@ -3342,7 +3342,7 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
}
break;
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;
}
}

View File

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

View File

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

View File

@ -297,7 +297,7 @@ struct timeval {
void lwip_socket_init(void);
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_getpeername (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_connect(int s, const struct sockaddr *name, socklen_t namelen);
int lwip_listen(int s, int backlog);
int lwip_recv(int s, void *mem, int len, unsigned int flags);
int lwip_read(int s, void *mem, int len);
int lwip_recvfrom(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, size_t len);
int lwip_recvfrom(int s, void *mem, size_t len, int flags,
struct sockaddr *from, socklen_t *fromlen);
int lwip_send(int s, const void *dataptr, int size, unsigned int flags);
int lwip_sendto(int s, const void *dataptr, int size, unsigned int flags,
struct sockaddr *to, socklen_t tolen);
int lwip_send(int s, const void *dataptr, size_t size, int flags);
int lwip_sendto(int s, const void *dataptr, size_t size, int flags,
const struct sockaddr *to, socklen_t tolen);
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,
struct timeval *timeout);
int lwip_ioctl(int s, long cmd, void *argp);