api.h, api_lib.c, api_msg.c, sockets.c: group the different NETCONN_UDPxxx code in only one part...

This commit is contained in:
fbernon 2007-05-23 17:46:53 +00:00
parent d1ef610822
commit 953d783a3e
5 changed files with 34 additions and 66 deletions

View File

@ -19,6 +19,10 @@ HISTORY
++ New features:
2007-05-23 Frédéric Bernon
* api.h, api_lib.c, api_msg.c, sockets.c: group the different NETCONN_UDPxxx
code in only one part...
2007-05-18 Simon Goldschmidt
* opt.h, memp.h, memp.c: Added option MEMP_OVERFLOW_CHECK to check for memp
elements to overflow. This is achieved by adding some bytes before and after

View File

@ -272,7 +272,6 @@ netconn_delete(struct netconn *conn)
sys_mbox_free(conn->recvmbox);
conn->recvmbox = SYS_MBOX_NULL;
}
/* Drain the acceptmbox. */
if (conn->acceptmbox != SYS_MBOX_NULL) {
@ -304,12 +303,10 @@ netconn_type(struct netconn *conn)
err_t
netconn_peer(struct netconn *conn, struct ip_addr *addr, u16_t *port)
{
switch (conn->type) {
switch (NETCONNTYPE_GROUP(conn->type)) {
case NETCONN_RAW:
/* return an error as connecting is only a helper for upper layers */
return ERR_CONN;
case NETCONN_UDPLITE:
case NETCONN_UDPNOCHKSUM:
case NETCONN_UDP:
if (conn->pcb.udp == NULL ||
((conn->pcb.udp->flags & UDP_FLAGS_CONNECTED) == 0))
@ -330,13 +327,11 @@ netconn_peer(struct netconn *conn, struct ip_addr *addr, u16_t *port)
err_t
netconn_addr(struct netconn *conn, struct ip_addr **addr, u16_t *port)
{
switch (conn->type) {
switch (NETCONNTYPE_GROUP(conn->type)) {
case NETCONN_RAW:
*addr = &(conn->pcb.raw->local_ip);
*port = conn->pcb.raw->protocol;
break;
case NETCONN_UDPLITE:
case NETCONN_UDPNOCHKSUM:
case NETCONN_UDP:
*addr = &(conn->pcb.udp->local_ip);
*port = conn->pcb.udp->local_port;
@ -390,7 +385,7 @@ netconn_connect(struct netconn *conn, struct ip_addr *addr, u16_t port)
}
msg.function = do_connect;
msg.msg.conn = conn;
msg.msg.conn = conn;
msg.msg.msg.bc.ipaddr = addr;
msg.msg.msg.bc.port = port;
tcpip_apimsg(&msg);
@ -407,7 +402,7 @@ netconn_disconnect(struct netconn *conn)
}
msg.function = do_disconnect;
msg.msg.conn = conn;
msg.msg.conn = conn;
tcpip_apimsg(&msg);
return conn->err;
@ -438,11 +433,11 @@ struct netconn *
netconn_accept(struct netconn *conn)
{
struct netconn *newconn;
if (conn == NULL) {
return NULL;
}
sys_arch_mbox_fetch(conn->acceptmbox, (void *)&newconn, 0);
/* Register event with callback */
if (conn->callback)

View File

@ -290,7 +290,7 @@ pcb_new(struct api_msg_msg *msg)
msg->conn->err = ERR_OK;
/* Allocate a PCB for this connection */
switch(msg->conn->type) {
switch(NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
msg->conn->pcb.raw = raw_new(msg->msg.n.proto);
@ -302,30 +302,14 @@ pcb_new(struct api_msg_msg *msg)
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDPLITE:
msg->conn->pcb.udp = udp_new();
if(msg->conn->pcb.udp == NULL) {
msg->conn->err = ERR_MEM;
break;
}
udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE);
udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn);
break;
case NETCONN_UDPNOCHKSUM:
msg->conn->pcb.udp = udp_new();
if(msg->conn->pcb.udp == NULL) {
msg->conn->err = ERR_MEM;
break;
}
udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_NOCHKSUM);
udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn);
break;
case NETCONN_UDP:
msg->conn->pcb.udp = udp_new();
if(msg->conn->pcb.udp == NULL) {
msg->conn->err = ERR_MEM;
break;
}
if (msg->conn->type==NETCONN_UDPLITE) udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE);
if (msg->conn->type==NETCONN_UDPNOCHKSUM) udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_NOCHKSUM);
udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn);
break;
#endif /* LWIP_UDP */
@ -363,15 +347,13 @@ void
do_delconn(struct api_msg_msg *msg)
{
if (msg->conn->pcb.tcp != NULL) {
switch (msg->conn->type) {
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
raw_remove(msg->conn->pcb.raw);
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDPLITE:
case NETCONN_UDPNOCHKSUM:
case NETCONN_UDP:
msg->conn->pcb.udp->recv_arg = NULL;
udp_remove(msg->conn->pcb.udp);
@ -419,15 +401,13 @@ do_bind(struct api_msg_msg *msg)
}
if (msg->conn->pcb.tcp != NULL) {
switch (msg->conn->type) {
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
msg->conn->err = raw_bind(msg->conn->pcb.raw,msg->msg.bc.ipaddr);
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDPLITE:
case NETCONN_UDPNOCHKSUM:
case NETCONN_UDP:
msg->conn->err = udp_bind(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port);
break;
@ -479,7 +459,7 @@ do_connect(struct api_msg_msg *msg)
}
}
switch (msg->conn->type) {
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
msg->conn->err = raw_connect(msg->conn->pcb.raw, msg->msg.bc.ipaddr);
@ -487,8 +467,6 @@ do_connect(struct api_msg_msg *msg)
break;
#endif /* LWIP_RAW */
#if LWIP_UDP
case NETCONN_UDPLITE:
case NETCONN_UDPNOCHKSUM:
case NETCONN_UDP:
msg->conn->err = udp_connect(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port);
sys_mbox_post(msg->conn->mbox, NULL);
@ -510,19 +488,11 @@ do_connect(struct api_msg_msg *msg)
void
do_disconnect(struct api_msg_msg *msg)
{
switch (msg->conn->type) {
#if LWIP_UDP
case NETCONN_UDPLITE:
case NETCONN_UDPNOCHKSUM:
case NETCONN_UDP:
if (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_UDP) {
udp_disconnect(msg->conn->pcb.udp);
break;
#endif /* LWIP_UDP */
case NETCONN_TCP:
case NETCONN_RAW:
/* nothing to do */
break;
}
#endif /* LWIP_UDP */
sys_mbox_post(msg->conn->mbox, NULL);
}
@ -559,7 +529,7 @@ do_send(struct api_msg_msg *msg)
{
if (msg->conn->err == ERR_OK) {
if (msg->conn->pcb.tcp != NULL) {
switch (msg->conn->type) {
switch (NETCONNTYPE_GROUP(msg->conn->type)) {
#if LWIP_RAW
case NETCONN_RAW:
if (msg->msg.b->addr == NULL) {
@ -570,8 +540,6 @@ do_send(struct api_msg_msg *msg)
break;
#endif
#if LWIP_UDP
case NETCONN_UDPLITE:
case NETCONN_UDPNOCHKSUM:
case NETCONN_UDP:
if (msg->msg.b->addr == NULL) {
msg->conn->err = udp_send(msg->conn->pcb.udp, msg->msg.b->p);
@ -664,20 +632,16 @@ do_join_leave_group(struct api_msg_msg *msg)
{
if (msg->conn->err == ERR_OK) {
if (msg->conn->pcb.tcp != NULL) {
switch (msg->conn->type) {
if (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_UDP) {
#if LWIP_UDP
case NETCONN_UDPLITE:
case NETCONN_UDPNOCHKSUM:
case NETCONN_UDP:
if (msg->msg.jl.join_or_leave == NETCONN_JOIN) {
msg->conn->err = igmp_joingroup ( netif_default, msg->msg.jl.multiaddr);
} else {
msg->conn->err = igmp_leavegroup( netif_default, msg->msg.jl.multiaddr);
}
break;
#endif /* LWIP_UDP */
#if (LWIP_TCP || LWIP_RAW)
default:
} else {
msg->conn->err = ERR_VAL;
#endif /* (LWIP_TCP || LWIP_RAW) */
}

View File

@ -1081,7 +1081,7 @@ int lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optl
break;
case SO_TYPE:
switch (sock->conn->type) {
switch (NETCONNTYPE_GROUP(sock->conn->type)) {
case NETCONN_RAW:
*(int*)optval = SOCK_RAW;
break;
@ -1089,8 +1089,6 @@ int lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optl
*(int*)optval = SOCK_STREAM;
break;
case NETCONN_UDP:
case NETCONN_UDPLITE:
case NETCONN_UDPNOCHKSUM:
*(int*)optval = SOCK_DGRAM;
break;
default: /* unrecognized socket type */

View File

@ -55,12 +55,19 @@ extern "C" {
#define NETCONN_NOCOPY 0x00
#define NETCONN_COPY 0x01
/* Helpers to process several netconn_types by the same code */
#define NETCONNTYPE_GROUP(t) (t&0xF0)
#define NETCONNTYPE_DATAGRAM(t) (t&0xE0)
enum netconn_type {
NETCONN_TCP,
NETCONN_UDP,
NETCONN_UDPLITE,
NETCONN_UDPNOCHKSUM,
NETCONN_RAW
/* NETCONN_TCP Group */
NETCONN_TCP = 0x10,
/* NETCONN_UDP Group */
NETCONN_UDP = 0x20,
NETCONN_UDPLITE = 0x21,
NETCONN_UDPNOCHKSUM= 0x22,
/* NETCONN_RAW Group */
NETCONN_RAW = 0x40
};
enum netconn_state {