full picoTCP stack integration. hasn't been stress-tested yet

This commit is contained in:
Joseph Henry
2016-10-18 16:38:09 -07:00
parent 4e386ac482
commit 844e8a0826
7 changed files with 234 additions and 90 deletions

View File

@@ -165,26 +165,19 @@ PICO_TREE_DECLARE(TCPTable, sockport_cmp);
struct pico_sockport *pico_get_sockport(uint16_t proto, uint16_t port) struct pico_sockport *pico_get_sockport(uint16_t proto, uint16_t port)
{ {
printf("pico_get_sockport\n");
struct pico_sockport test = INIT_SOCKPORT; struct pico_sockport test = INIT_SOCKPORT;
test.number = port; test.number = port;
if (proto == PICO_PROTO_UDP){ if (proto == PICO_PROTO_UDP){
printf("pico_get_sockport: proto UDP?\n");
return pico_tree_findKey(&UDPTable, &test); return pico_tree_findKey(&UDPTable, &test);
} }
else if (proto == PICO_PROTO_TCP){ else if (proto == PICO_PROTO_TCP){
printf("pico_get_sockport: proto TCP?\n");
return pico_tree_findKey(&TCPTable, &test); return pico_tree_findKey(&TCPTable, &test);
} }
else else
{ { return NULL;
printf("pico_get_sockport: proto NULL?\n");
return NULL;
} }
} }
@@ -335,7 +328,6 @@ int pico_is_port_free(uint16_t proto, uint16_t port, void *addr, void *net)
static int pico_check_socket(struct pico_socket *s) static int pico_check_socket(struct pico_socket *s)
{ {
printf("pico_check_socket\n");
struct pico_sockport *test; struct pico_sockport *test;
struct pico_socket *found; struct pico_socket *found;
struct pico_tree_node *index; struct pico_tree_node *index;
@@ -343,8 +335,6 @@ static int pico_check_socket(struct pico_socket *s)
test = pico_get_sockport(PROTO(s), s->local_port); test = pico_get_sockport(PROTO(s), s->local_port);
if (!test) { if (!test) {
printf("!test\n");
return -1; return -1;
} }
@@ -354,9 +344,6 @@ static int pico_check_socket(struct pico_socket *s)
return 0; return 0;
} }
} }
printf("no key found\n");
return -1; return -1;
} }
@@ -378,7 +365,6 @@ struct pico_socket *pico_sockets_find(uint16_t local, uint16_t remote)
} }
} }
} }
return sock; return sock;
} }
@@ -728,25 +714,17 @@ int pico_socket_read(struct pico_socket *s, void *buf, int len)
static int pico_socket_write_check_state(struct pico_socket *s) static int pico_socket_write_check_state(struct pico_socket *s)
{ {
printf("pico_socket_write_check_state\n");
if ((s->state & PICO_SOCKET_STATE_BOUND) == 0) { if ((s->state & PICO_SOCKET_STATE_BOUND) == 0) {
printf("PICO_ERR_EIO\n");
pico_err = PICO_ERR_EIO; pico_err = PICO_ERR_EIO;
return -1; return -1;
} }
if ((s->state & PICO_SOCKET_STATE_CONNECTED) == 0) { if ((s->state & PICO_SOCKET_STATE_CONNECTED) == 0) {
printf("PICO_ERR_ENOTCONN\n");
pico_err = PICO_ERR_ENOTCONN; pico_err = PICO_ERR_ENOTCONN;
return -1; return -1;
} }
if (s->state & PICO_SOCKET_STATE_SHUT_LOCAL) { /* check if in shutdown state */ if (s->state & PICO_SOCKET_STATE_SHUT_LOCAL) { /* check if in shutdown state */
printf("PICO_ERR_ESHUTDOWN\n");
pico_err = PICO_ERR_ESHUTDOWN; pico_err = PICO_ERR_ESHUTDOWN;
return -1; return -1;
} }
@@ -756,11 +734,7 @@ static int pico_socket_write_check_state(struct pico_socket *s)
static int pico_socket_write_attempt(struct pico_socket *s, const void *buf, int len) static int pico_socket_write_attempt(struct pico_socket *s, const void *buf, int len)
{ {
printf("pico_socket_write_attempt\n");
if (pico_socket_write_check_state(s) < 0) { if (pico_socket_write_check_state(s) < 0) {
printf("pico_socket_write_check_state = -1\n");
return -1; return -1;
} else { } else {
return pico_socket_sendto(s, buf, len, &s->remote_addr, s->remote_port); return pico_socket_sendto(s, buf, len, &s->remote_addr, s->remote_port);
@@ -769,18 +743,13 @@ static int pico_socket_write_attempt(struct pico_socket *s, const void *buf, int
int pico_socket_write(struct pico_socket *s, const void *buf, int len) int pico_socket_write(struct pico_socket *s, const void *buf, int len)
{ {
printf("pico_socket_write\n");
if (!s || buf == NULL) { if (!s || buf == NULL) {
printf("PICO_ERR_EINVAL\n");
pico_err = PICO_ERR_EINVAL; pico_err = PICO_ERR_EINVAL;
return -1; return -1;
} else { } else {
/* check if exists in tree */ /* check if exists in tree */
/* See task #178 */ /* See task #178 */
if (pico_check_socket(s) != 0) { if (pico_check_socket(s) != 0) {
printf("PICO_ERR_EINVAL?\n");
pico_err = PICO_ERR_EINVAL; pico_err = PICO_ERR_EINVAL;
return -1; return -1;
} }

View File

@@ -121,7 +121,7 @@ static NetconEthernetTap *picotap;
DEBUG_ERROR("device init failed"); DEBUG_ERROR("device init failed");
return; return;
} }
DEBUG_INFO("successfully initialized device with IPV4 address"); // DEBUG_INFO("device initialized as ipv4_addr = %s", ipv4_str);
// picostack->__pico_icmp4_ping("10.8.8.1", 20, 1000, 10000, 64, cb_ping); // picostack->__pico_icmp4_ping("10.8.8.1", 20, 1000, 10000, 64, cb_ping);
} }
#elif defined(SDK_IPV6) #elif defined(SDK_IPV6)
@@ -144,40 +144,123 @@ static NetconEthernetTap *picotap;
DEBUG_ERROR("device init failed"); DEBUG_ERROR("device init failed");
return; return;
} }
DEBUG_INFO("successfully initialized device with IPV6 address"); DEBUG_INFO("device initialized as ipv6_addr = %s", ipv6_str);
} }
#endif #endif
} }
} }
static void cb_tcpclient(uint16_t ev, struct pico_socket *s) // RX
// Copies data onto the RX buffer and notifies the system that data can be read, buffer will be emptied by pico_handleRead()
static void pico_cb_tcp_read(struct pico_socket *s)
{
DEBUG_INFO();
Connection *conn = picotap->getConnection(s);
if(conn) {
int r;
do {
//int avail = DEFAULT_TCP_RX_BUF_SZ - conn->rxsz;
//if(avail) {
r = picotap->picostack->__pico_socket_read(s, conn->rxbuf + (conn->rxsz), ZT_MAX_MTU);
picotap->_phy.setNotifyWritable(conn->sock, true);
DEBUG_ATTN("read=%d", r);
if (r > 0) {
conn->rxsz += r;
}
//}
if (r < 0) {
exit(5);
}
}
while(r > 0);
return;
}
DEBUG_ERROR("invalid connection");
}
// TX
static void pico_cb_tcp_write(struct pico_socket *s)
{
DEBUG_INFO();
// Only called from a locked context, no need to lock anything
Connection *conn = picotap->getConnection(s);
if(conn->txsz > 0)
{
DEBUG_ATTN("%d bytes ready to be written", conn->txsz);
int r = conn->txsz < ZT_MAX_MTU ? conn->txsz : ZT_MAX_MTU;
if((r = picotap->picostack->__pico_socket_write(s, &conn->txbuf, r)) < 0) {
DEBUG_ERROR("unable to write to pico_socket=%p", (void*)s);
return;
}
int sz = (conn->txsz)-r;
if(sz)
memmove(&conn->txbuf, (conn->txbuf+r), sz);
conn->txsz -= r;
int max = conn->type == SOCK_STREAM ? DEFAULT_TCP_TX_BUF_SZ : DEFAULT_UDP_TX_BUF_SZ;
DEBUG_TRANS("TCP TX ---> :: {TX: %.3f%%, RX: %.3f%%, sock=%p} :: %d bytes",
(float)conn->txsz / (float)max, (float)conn->rxsz / max, (void*)&conn->sock, r);
return;
}
}
static void pico_cb_tcp(uint16_t ev, struct pico_socket *s)
{ {
DEBUG_INFO(); DEBUG_INFO("pico_socket=%p", (void*)s);
/* Mutex::Lock _l(picotap->_tcpconns_m);
DEBUG_INFO("ACTIVITY on pico_socket!\n"); Connection *conn = picotap->getConnection(s);
if (ev & PICO_SOCK_EV_RD) { if(!conn) {
DEBUG_INFO("PICO_SOCK_EV_RD\n"); DEBUG_ERROR(" invalid connection");
} }
if (ev & PICO_SOCK_EV_RD) {
pico_cb_tcp_read(s);
}
// Accept connection (analogous to lwip_nc_accept)
if (ev & PICO_SOCK_EV_CONN) { if (ev & PICO_SOCK_EV_CONN) {
DEBUG_INFO("Connection established with server.\n"); DEBUG_INFO(" connection established with server.");
uint32_t peer;
uint16_t port;
struct pico_socket *client = picotap->picostack->__pico_socket_accept(s, &peer, &port);
if(!client) {
DEBUG_ERROR(" there was an error accepting the connection");
}
ZT_PHY_SOCKFD_TYPE fds[2];
if(socketpair(PF_LOCAL, SOCK_STREAM, 0, fds) < 0) {
if(errno < 0) {
picotap->sendReturnValue(conn, -1, errno);
DEBUG_ERROR(" unable to create socketpair");
return;
}
}
Connection *newTcpConn = new Connection();
picotap->_Connections.push_back(newTcpConn);
newTcpConn->type = SOCK_STREAM;
newTcpConn->sock = picotap->_phy.wrapSocket(fds[0], newTcpConn);
newTcpConn->picosock = client;
int fd = picotap->_phy.getDescriptor(conn->sock);
if(sock_fd_write(fd, fds[1]) < 0) {
DEBUG_ERROR("error sending new fd to client application");
}
} }
if (ev & PICO_SOCK_EV_FIN) { if (ev & PICO_SOCK_EV_FIN) {
DEBUG_INFO("Socket closed. Exit normally. \n"); DEBUG_INFO(" socket closed. Exit normally.");
//picotap->__pico_timer_add(2000, compare_results, NULL); //picotap->__pico_timer_add(2000, compare_results, NULL);
} }
if (ev & PICO_SOCK_EV_ERR) { if (ev & PICO_SOCK_EV_ERR) {
DEBUG_INFO("Socket error received:. Bailing out.\n", strerror(pico_err)); DEBUG_INFO(" socket error received:. Bailing out." /*, strerror(pico_err)*/);
exit(1); exit(1);
} }
if (ev & PICO_SOCK_EV_CLOSE) { if (ev & PICO_SOCK_EV_CLOSE) {
DEBUG_INFO("Socket received close from peer - Wrong case if not all client data sent!\n"); DEBUG_INFO(" socket received close from peer - Wrong case if not all client data sent!");
picotap->picostack->__pico_socket_close(s); picotap->picostack->__pico_socket_close(s);
return; return;
} }
if (ev & PICO_SOCK_EV_WR) { if (ev & PICO_SOCK_EV_WR) {
printf("PICO_SOCK_EV_WR\n"); pico_cb_tcp_write(s);
} }
*/
} }
static void cb_ping(struct pico_icmp4_stats *s) static void cb_ping(struct pico_icmp4_stats *s)
@@ -200,7 +283,7 @@ static NetconEthernetTap *picotap;
static int pico_eth_send(struct pico_device *dev, void *buf, int len) static int pico_eth_send(struct pico_device *dev, void *buf, int len)
{ {
DEBUG_INFO("len = %d", len); DEBUG_INFO("len=%d", len);
struct eth_hdr *ethhdr; struct eth_hdr *ethhdr;
ethhdr = (struct eth_hdr *)buf; ethhdr = (struct eth_hdr *)buf;
@@ -216,9 +299,8 @@ static NetconEthernetTap *picotap;
static int pico_eth_poll(struct pico_device *dev, int loop_score) static int pico_eth_poll(struct pico_device *dev, int loop_score)
{ {
DEBUG_INFO(); // DEBUG_EXTRA();
// OPTIMIZATION: The copy logic and/or buffer structure should be reworked for better performance after the BETA // OPTIMIZATION: The copy logic and/or buffer structure should be reworked for better performance after the BETA
// DEBUG_INFO();
// ZeroTier::NetconEthernetTap *tap = (ZeroTier::NetconEthernetTap*)netif->state; // ZeroTier::NetconEthernetTap *tap = (ZeroTier::NetconEthernetTap*)netif->state;
Mutex::Lock _l(picotap->_pico_frame_rxbuf_m); Mutex::Lock _l(picotap->_pico_frame_rxbuf_m);
@@ -232,13 +314,13 @@ static NetconEthernetTap *picotap;
unsigned int len = 0; unsigned int len = 0;
memcpy(&len, picotap->pico_frame_rxbuf, sizeof(len)); // get frame len memcpy(&len, picotap->pico_frame_rxbuf, sizeof(len)); // get frame len
DEBUG_ATTN("reading frame len = %ld", len); //DEBUG_EXTRA("reading frame len = %ld", len);
memcpy(frame, picotap->pico_frame_rxbuf + sizeof(len), len); // get frame data memcpy(frame, picotap->pico_frame_rxbuf + sizeof(len), len); // get frame data
memmove(picotap->pico_frame_rxbuf, picotap->pico_frame_rxbuf + sizeof(len) + len, ZT_MAX_MTU-(sizeof(len) + len)); memmove(picotap->pico_frame_rxbuf, picotap->pico_frame_rxbuf + sizeof(len) + len, ZT_MAX_MTU-(sizeof(len) + len));
int rx_ret = picotap->picostack->__pico_stack_recv(dev, (uint8_t*)frame, len); int rx_ret = picotap->picostack->__pico_stack_recv(dev, (uint8_t*)frame, len);
picotap->pico_frame_rxbuf_tot-=(sizeof(len) + len); picotap->pico_frame_rxbuf_tot-=(sizeof(len) + len);
DEBUG_ATTN("rx_ret = %d", rx_ret); //DEBUG_EXTRA("rx_ret = %d", rx_ret);
DEBUG_EXTRA("RX frame buffer %3f full", (float)(picotap->pico_frame_rxbuf_tot) / (float)(MAX_PICO_FRAME_RX_BUF_SZ)); //DEBUG_EXTRA("RX frame buffer %3f full", (float)(picotap->pico_frame_rxbuf_tot) / (float)(MAX_PICO_FRAME_RX_BUF_SZ));
loop_score--; loop_score--;
} }
//DEBUG_ATTN("loop_score = %d", loop_score); //DEBUG_ATTN("loop_score = %d", loop_score);
@@ -250,9 +332,9 @@ static NetconEthernetTap *picotap;
DEBUG_INFO(); DEBUG_INFO();
struct pico_socket * psock; struct pico_socket * psock;
#if defined(SDK_IPV4) #if defined(SDK_IPV4)
psock = picotap->picostack->__pico_socket_open(PICO_PROTO_IPV4, PICO_PROTO_TCP, &cb_tcpclient); psock = picotap->picostack->__pico_socket_open(PICO_PROTO_IPV4, PICO_PROTO_TCP, &pico_cb_tcp);
#elif defined(SDK_IPV6) #elif defined(SDK_IPV6)
psock = picotap->picostack->__pico_socket_open(PICO_PROTO_IPV6, PICO_PROTO_TCP, &cb_tcpclient); psock = picotap->picostack->__pico_socket_open(PICO_PROTO_IPV6, PICO_PROTO_TCP, &pico_cb_tcp);
#endif #endif
if(psock) { if(psock) {
DEBUG_ATTN("psock = %p", (void*)psock); DEBUG_ATTN("psock = %p", (void*)psock);
@@ -322,11 +404,6 @@ static NetconEthernetTap *picotap;
struct sockaddr_in *addr = (struct sockaddr_in *) &connect_rpc->addr; struct sockaddr_in *addr = (struct sockaddr_in *) &connect_rpc->addr;
pico_address paddr; pico_address paddr;
int ret; int ret;
union pico_address dst = {
.ip4 = {0}, .ip6 = {{0}}
};
// TODO: Rewrite this // TODO: Rewrite this
#if defined(SDK_IPV4) #if defined(SDK_IPV4)
struct pico_ip4 zaddr; struct pico_ip4 zaddr;
@@ -376,35 +453,116 @@ static NetconEthernetTap *picotap;
char ipv4_str[INET_ADDRSTRLEN]; char ipv4_str[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &(in4->sin_addr), ipv4_str, INET_ADDRSTRLEN); inet_ntop(AF_INET, &(in4->sin_addr), ipv4_str, INET_ADDRSTRLEN);
picotap->picostack->__pico_string_to_ipv4(ipv4_str, &(zaddr.addr)); picotap->picostack->__pico_string_to_ipv4(ipv4_str, &(zaddr.addr));
ret = picotap->picostack->__pico_socket_connect(conn->picosock, &zaddr, addr->sin_port); ret = picotap->picostack->__pico_socket_bind(conn->picosock, &zaddr, addr->sin_port);
#elif defined(SDK_IPV6) #elif defined(SDK_IPV6)
struct pico_ip6 zaddr; struct pico_ip6 zaddr;
struct sockaddr_in6 *in6 = (struct sockaddr_in6*)&bind_rpc->addr; struct sockaddr_in6 *in6 = (struct sockaddr_in6*)&bind_rpc->addr;
char ipv6_str[INET6_ADDRSTRLEN]; char ipv6_str[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6, &(in6->sin6_addr), ipv6_str, INET6_ADDRSTRLEN); inet_ntop(AF_INET6, &(in6->sin6_addr), ipv6_str, INET6_ADDRSTRLEN);
picotap->picostack->__pico_string_to_ipv6(ipv6_str, zaddr.addr); picotap->picostack->__pico_string_to_ipv6(ipv6_str, zaddr.addr);
ret = picotap->picostack->__pico_socket_connect(conn->picosock, &zaddr, addr->sin_port); ret = picotap->picostack->__pico_socket_bind(conn->picosock, &zaddr, (uint16_t*)&(addr->sin_port));
#endif #endif
if(ret < 0) { if(ret < 0) {
DEBUG_ERROR("unable to bind pico_socket(%p)", (void*)(conn->picosock)); DEBUG_ERROR("unable to bind pico_socket(%p)", (void*)(conn->picosock));
if(ret == PICO_ERR_EINVAL) {
DEBUG_ERROR("PICO_ERR_EINVAL - invalid argument");
picotap->sendReturnValue(rpcSock, -1, EINVAL);
}
if(ret == PICO_ERR_ENOMEM) {
DEBUG_ERROR("PICO_ERR_ENOMEM - not enough space");
picotap->sendReturnValue(rpcSock, -1, ENOMEM);
}
if(ret == PICO_ERR_ENXIO) {
DEBUG_ERROR("PICO_ERR_ENXIO - no such device or address");
picotap->sendReturnValue(rpcSock, -1, ENXIO);
}
} }
picotap->sendReturnValue(rpcSock, ERR_OK, ERR_OK); // success
} }
static void pico_handleListen(PhySocket *sock, PhySocket *rpcSock, void **uptr, struct listen_st *listen_rpc) static void pico_handleListen(PhySocket *sock, PhySocket *rpcSock, void **uptr, struct listen_st *listen_rpc)
{ {
DEBUG_INFO();
Connection *conn = picotap->getConnection(sock); Connection *conn = picotap->getConnection(sock);
DEBUG_ATTN("conn = %p", (void*)conn);
if(!sock || !conn) { if(!sock || !conn) {
DEBUG_ERROR("invalid connection"); DEBUG_ERROR("invalid connection");
return; return;
} }
int backlog = 1; int ret, backlog = 1;
picotap->picostack->__pico_socket_listen(conn->picosock, backlog); if((ret = picotap->picostack->__pico_socket_listen(conn->picosock, backlog)) < 0)
{
if(ret == PICO_ERR_EINVAL) {
DEBUG_ERROR("PICO_ERR_EINVAL - invalid argument");
picotap->sendReturnValue(rpcSock, -1, EINVAL);
}
if(ret == PICO_ERR_EISCONN) {
DEBUG_ERROR("PICO_ERR_EISCONN - socket is connected");
picotap->sendReturnValue(rpcSock, -1, EISCONN);
}
}
picotap->sendReturnValue(rpcSock, ERR_OK, ERR_OK); // success
} }
static void pico_handleRead(PhySocket *sock,void **uptr,bool lwip_invoked) static void pico_handleRead(PhySocket *sock,void **uptr,bool lwip_invoked)
{ {
/*
int payload_sz, addr_sz_offset = sizeof(struct sockaddr_storage);
memcpy(&payload_sz, conn->rxbuf + addr_sz_offset, sizeof(int)); // OPT:
// extract address
struct sockaddr_storage addr;
memcpy(&addr, conn->rxbuf, addr_sz_offset);
if(n == ZT_MAX_MTU) {
if(conn->rxsz-n > 0) // If more remains on buffer
memcpy(conn->rxbuf, conn->rxbuf+ZT_MAX_MTU, conn->rxsz - ZT_MAX_MTU);
conn->rxsz -= ZT_MAX_MTU;
// DGRAM
if(conn->type==SOCK_DGRAM){
_phy.setNotifyWritable(conn->sock, false);
#if DEBUG_LEVEL >= MSG_TRANSFER
struct sockaddr_in * addr_in2 = (struct sockaddr_in *)&addr;
int port = lwipstack->__lwip_ntohs(addr_in2->sin_port);
int ip = addr_in2->sin_addr.s_addr;
unsigned char d[4];
d[0] = ip & 0xFF;
d[1] = (ip >> 8) & 0xFF;
d[2] = (ip >> 16) & 0xFF;
d[3] = (ip >> 24) & 0xFF;
DEBUG_TRANS("UDP RX <--- :: {TX: %.3f%%, RX: %d, sock=%p} :: payload = %d bytes (src_addr=%d.%d.%d.%d:%d)",
(float)conn->txsz / max, conn->rxsz, (void*)conn->sock, payload_sz, d[0],d[1],d[2],d[3], port);
#endif
}
// STREAM
//DEBUG_INFO("phyOnUnixWritable(): tid = %d\n", pthread_mach_thread_np(pthread_self()));
if(conn->type==SOCK_STREAM) { // Only acknolwedge receipt of TCP packets
lwipstack->__tcp_recved(conn->TCP_pcb, n);
DEBUG_TRANS("TCP RX <--- :: {TX: %.3f%%, RX: %.3f%%, sock=%p} :: %ld bytes",
(float)conn->txsz / max, (float)conn->rxsz / max, (void*)conn->sock, n);
}
} else {
DEBUG_EXTRA(" errno = %d, rxsz = %d", errno, conn->rxsz);
_phy.setNotifyWritable(conn->sock, false);
}
*/
DEBUG_INFO(); DEBUG_INFO();
Connection *conn = picotap->getConnection(sock);
if(conn && conn->rxsz) {
float max = conn->type == SOCK_STREAM ? (float)DEFAULT_TCP_RX_BUF_SZ : (float)DEFAULT_UDP_RX_BUF_SZ;
long n = picotap->_phy.streamSend(conn->sock, conn->rxbuf, ZT_MAX_MTU);
DEBUG_ATTN("wrote %d bytes to client application", n);
}
//if((ret = picotap->picostack->__pico_socket_read(s, buf, len)) < 0) { //if((ret = picotap->picostack->__pico_socket_read(s, buf, len)) < 0) {
// DEBUG_ERROR("unable to read from pico_socket(%p)", (void*)(conn->picosock)) // DEBUG_ERROR("unable to read from pico_socket(%p)", (void*)(conn->picosock))
//} //}
@@ -413,6 +571,15 @@ static NetconEthernetTap *picotap;
static void pico_handleClose(Connection *conn) static void pico_handleClose(Connection *conn)
{ {
DEBUG_INFO(); DEBUG_INFO();
int ret;
if(conn && conn->picosock) {
if((ret = picotap->picostack->__pico_socket_close(conn->picosock)) < 0) {
DEBUG_ERROR("error closing pico_socket(%p)", (void*)(conn->picosock));
// sendReturnValue()
}
return;
}
DEBUG_ERROR("invalid connection or pico_socket");
} }
@@ -696,7 +863,7 @@ void NetconEthernetTap::lwIP_rx(const MAC &from,const MAC &to,unsigned int ether
void NetconEthernetTap::picoTCP_rx(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len) void NetconEthernetTap::picoTCP_rx(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
{ {
DEBUG_INFO(); //DEBUG_INFO();
// Since picoTCP only allows the reception of frames from within the polling function, we // Since picoTCP only allows the reception of frames from within the polling function, we
// must enqueue each frame into a memory structure shared by both threads. This structure will // must enqueue each frame into a memory structure shared by both threads. This structure will
Mutex::Lock _l(_pico_frame_rxbuf_m); Mutex::Lock _l(_pico_frame_rxbuf_m);
@@ -720,7 +887,8 @@ void NetconEthernetTap::picoTCP_rx(const MAC &from,const MAC &to,unsigned int et
memcpy(pico_frame_rxbuf + pico_frame_rxbuf_tot + sizeof(newlen), &ethhdr, sizeof(ethhdr)); // new eth header memcpy(pico_frame_rxbuf + pico_frame_rxbuf_tot + sizeof(newlen), &ethhdr, sizeof(ethhdr)); // new eth header
memcpy(pico_frame_rxbuf + pico_frame_rxbuf_tot + sizeof(newlen) + sizeof(ethhdr), data, len); // frame data memcpy(pico_frame_rxbuf + pico_frame_rxbuf_tot + sizeof(newlen) + sizeof(ethhdr), data, len); // frame data
pico_frame_rxbuf_tot += len + sizeof(len) + sizeof(ethhdr); pico_frame_rxbuf_tot += len + sizeof(len) + sizeof(ethhdr);
DEBUG_INFO("RX frame buffer %3f full", (float)pico_frame_rxbuf_tot / (float)(1024 * 1024)); //DEBUG_INFO("RX frame buffer %3f full", (float)pico_frame_rxbuf_tot / (float)(1024 * 1024));
DEBUG_INFO("len=%d", len);
} }
void NetconEthernetTap::jip_rx(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len) void NetconEthernetTap::jip_rx(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
@@ -901,6 +1069,15 @@ Connection *NetconEthernetTap::getConnection(PhySocket *sock)
return NULL; return NULL;
} }
Connection *NetconEthernetTap::getConnection(struct pico_socket *sock)
{
for(size_t i=0;i<_Connections.size();++i) {
if(_Connections[i]->picosock == sock)
return _Connections[i];
}
return NULL;
}
void NetconEthernetTap::closeConnection(PhySocket *sock) void NetconEthernetTap::closeConnection(PhySocket *sock)
{ {
DEBUG_EXTRA("sock=%p", (void*)sock); DEBUG_EXTRA("sock=%p", (void*)sock);
@@ -1718,7 +1895,7 @@ Connection * NetconEthernetTap::handleSocket(PhySocket *sock, void **uptr, struc
// picoTCP // picoTCP
#if defined(SDK_PICOTCP) #if defined(SDK_PICOTCP)
pico_handleSocket(sock, uptr, socket_rpc); return pico_handleSocket(sock, uptr, socket_rpc);
#endif #endif
// lwIP // lwIP

View File

@@ -478,6 +478,11 @@ namespace ZeroTier {
*/ */
Connection *getConnection(PhySocket *sock); Connection *getConnection(PhySocket *sock);
/*
* Returns a pointer to a TcpConnection associated with a given pico_socket
*/
Connection *getConnection(struct pico_socket *socket);
/* /*
* Closes a TcpConnection, associated LWIP PCB strcuture, * Closes a TcpConnection, associated LWIP PCB strcuture,
* PhySocket, and underlying file descriptor * PhySocket, and underlying file descriptor

View File

@@ -367,9 +367,7 @@ pthread_key_t thr_id_key;
if(fd == 0 || fd == 1 || fd == 2) if(fd == 0 || fd == 1 || fd == 2)
return(realbind(fd, addr, addrlen)); return(realbind(fd, addr, addrlen));
struct sockaddr_in *connaddr; // TODO: Revisit
struct sockaddr_in6 *connaddr6;
char addrstr[INET6_ADDRSTRLEN]; char addrstr[INET6_ADDRSTRLEN];
if(addr->sa_family == AF_INET) { if(addr->sa_family == AF_INET) {
struct sockaddr_in *connaddr = (struct sockaddr_in *)addr; struct sockaddr_in *connaddr = (struct sockaddr_in *)addr;
@@ -550,7 +548,7 @@ pthread_key_t thr_id_key;
#endif #endif
DEBUG_INFO("fd=%d", fd); DEBUG_INFO("fd=%d", fd);
if(!connected_to_service(fd)) { if(!connected_to_service(fd)) {
DEBUG_ERROR("fd=%d not used by service"); DEBUG_ERROR("fd=%d not used by service", fd);
return realgetsockname(fd, addr, addrlen); return realgetsockname(fd, addr, addrlen);
} }
return zts_getsockname(fd, addr, addrlen); return zts_getsockname(fd, addr, addrlen);
@@ -578,7 +576,7 @@ pthread_key_t thr_id_key;
if (!check_intercept_enabled()) if (!check_intercept_enabled())
return realsyscall(number,a,b,c,d,e,f); return realsyscall(number,a,b,c,d,e,f);
DEBUG_INFO("number=%u", number); DEBUG_INFO("number=%ld", number);
#if defined(__i386__) #if defined(__i386__)
// TODO: Implement for 32-bit systems: syscall(__NR_socketcall, 18, args); // TODO: Implement for 32-bit systems: syscall(__NR_socketcall, 18, args);

View File

@@ -56,12 +56,9 @@
#define PICO_DEVICE_INIT_SIG struct pico_device *dev, const char *name, uint8_t *mac #define PICO_DEVICE_INIT_SIG struct pico_device *dev, const char *name, uint8_t *mac
#define PICO_STACK_RECV_SIG struct pico_device *dev, uint8_t *buffer, uint32_t len #define PICO_STACK_RECV_SIG struct pico_device *dev, uint8_t *buffer, uint32_t len
#define PICO_ICMP4_PING_SIG char *dst, int count, int interval, int timeout, int size, void (*cb)(struct pico_icmp4_stats *) #define PICO_ICMP4_PING_SIG char *dst, int count, int interval, int timeout, int size, void (*cb)(struct pico_icmp4_stats *)
//
#define PICO_TIMER_ADD_SIG pico_time expire, void (*timer)(pico_time, void *), void *arg #define PICO_TIMER_ADD_SIG pico_time expire, void (*timer)(pico_time, void *), void *arg
#define PICO_STRING_TO_IPV4_SIG const char *ipstr, uint32_t *ip #define PICO_STRING_TO_IPV4_SIG const char *ipstr, uint32_t *ip
#define PICO_STRING_TO_IPV6_SIG const char *ipstr, uint8_t *ip #define PICO_STRING_TO_IPV6_SIG const char *ipstr, uint8_t *ip
#define PICO_SOCKET_SETOPTION_SIG struct pico_socket *s, int option, void *value #define PICO_SOCKET_SETOPTION_SIG struct pico_socket *s, int option, void *value
#define PICO_SOCKET_SEND_SIG struct pico_socket *s, const void *buf, int len #define PICO_SOCKET_SEND_SIG struct pico_socket *s, const void *buf, int len
#define PICO_SOCKET_SENDTO_SIG struct pico_socket *s, const void *buf, int len, void *dst, uint16_t remote_port #define PICO_SOCKET_SENDTO_SIG struct pico_socket *s, const void *buf, int len, void *dst, uint16_t remote_port
@@ -74,7 +71,7 @@
#define PICO_SOCKET_WRITE_SIG struct pico_socket *s, const void *buf, int len #define PICO_SOCKET_WRITE_SIG struct pico_socket *s, const void *buf, int len
#define PICO_SOCKET_CLOSE_SIG struct pico_socket *s #define PICO_SOCKET_CLOSE_SIG struct pico_socket *s
#define PICO_SOCKET_SHUTDOWN_SIG struct pico_socket *s, int mode #define PICO_SOCKET_SHUTDOWN_SIG struct pico_socket *s, int mode
#define PICO_SOCKET_ACCEPT_SIG struct pico_socket *s, void *orig, uint16_t *port
#define PICO_IPV6_LINK_ADD_SIG struct pico_device *dev, struct pico_ip6 address, struct pico_ip6 netmask #define PICO_IPV6_LINK_ADD_SIG struct pico_device *dev, struct pico_ip6 address, struct pico_ip6 netmask
namespace ZeroTier { namespace ZeroTier {
@@ -113,13 +110,11 @@ namespace ZeroTier {
int (*_pico_device_init)(PICO_DEVICE_INIT_SIG); int (*_pico_device_init)(PICO_DEVICE_INIT_SIG);
int32_t (*_pico_stack_recv)(PICO_STACK_RECV_SIG); int32_t (*_pico_stack_recv)(PICO_STACK_RECV_SIG);
int (*_pico_icmp4_ping)(PICO_ICMP4_PING_SIG); int (*_pico_icmp4_ping)(PICO_ICMP4_PING_SIG);
int (*_pico_string_to_ipv6)(PICO_STRING_TO_IPV6_SIG); int (*_pico_string_to_ipv6)(PICO_STRING_TO_IPV6_SIG);
int (*_pico_socket_setoption)(PICO_SOCKET_SETOPTION_SIG); int (*_pico_socket_setoption)(PICO_SOCKET_SETOPTION_SIG);
uint32_t (*_pico_timer_add)(PICO_TIMER_ADD_SIG); uint32_t (*_pico_timer_add)(PICO_TIMER_ADD_SIG);
int (*_pico_socket_send)(PICO_SOCKET_SEND_SIG); int (*_pico_socket_send)(PICO_SOCKET_SEND_SIG);
int (*_pico_socket_recv)(PICO_SOCKET_RECV_SIG); int (*_pico_socket_recv)(PICO_SOCKET_RECV_SIG);
struct pico_socket * (*_pico_socket_open)(PICO_SOCKET_OPEN_SIG); struct pico_socket * (*_pico_socket_open)(PICO_SOCKET_OPEN_SIG);
int (*_pico_socket_bind)(PICO_SOCKET_BIND_SIG); int (*_pico_socket_bind)(PICO_SOCKET_BIND_SIG);
int (*_pico_socket_connect)(PICO_SOCKET_CONNECT_SIG); int (*_pico_socket_connect)(PICO_SOCKET_CONNECT_SIG);
@@ -129,6 +124,8 @@ namespace ZeroTier {
int (*_pico_socket_close)(PICO_SOCKET_CLOSE_SIG); int (*_pico_socket_close)(PICO_SOCKET_CLOSE_SIG);
int (*_pico_socket_shutdown)(PICO_SOCKET_SHUTDOWN_SIG); int (*_pico_socket_shutdown)(PICO_SOCKET_SHUTDOWN_SIG);
struct pico_socket *(*_pico_socket_accept)(PICO_SOCKET_ACCEPT_SIG);
int (*_pico_ipv6_link_add)(PICO_IPV6_LINK_ADD_SIG); int (*_pico_ipv6_link_add)(PICO_IPV6_LINK_ADD_SIG);
pico_err_t (*_get_pico_err)(void); pico_err_t (*_get_pico_err)(void);
@@ -172,13 +169,11 @@ namespace ZeroTier {
_pico_device_init = (int(*)(PICO_DEVICE_INIT_SIG))&pico_device_init; _pico_device_init = (int(*)(PICO_DEVICE_INIT_SIG))&pico_device_init;
_pico_stack_recv = (int32_t(*)(PICO_STACK_RECV_SIG))&pico_stack_recv; _pico_stack_recv = (int32_t(*)(PICO_STACK_RECV_SIG))&pico_stack_recv;
_pico_icmp4_ping = (int(*)(PICO_ICMP4_PING_SIG))&pico_icmp4_ping; _pico_icmp4_ping = (int(*)(PICO_ICMP4_PING_SIG))&pico_icmp4_ping;
_pico_string_to_ipv6 = (int(*)(PICO_STRING_TO_IPV6_SIG))&pico_string_to_ipv6; _pico_string_to_ipv6 = (int(*)(PICO_STRING_TO_IPV6_SIG))&pico_string_to_ipv6;
_pico_socket_setoption = (int(*)(PICO_SOCKET_SETOPTION_SIG))&pico_socket_setoption; _pico_socket_setoption = (int(*)(PICO_SOCKET_SETOPTION_SIG))&pico_socket_setoption;
_pico_timer_add = (uint32_t(*)(PICO_TIMER_ADD_SIG))&pico_timer_add; _pico_timer_add = (uint32_t(*)(PICO_TIMER_ADD_SIG))&pico_timer_add;
_pico_socket_send = (int(*)(PICO_SOCKET_SEND_SIG))&pico_socket_send; _pico_socket_send = (int(*)(PICO_SOCKET_SEND_SIG))&pico_socket_send;
_pico_socket_recv = (int(*)(PICO_SOCKET_RECV_SIG))&pico_socket_recv; _pico_socket_recv = (int(*)(PICO_SOCKET_RECV_SIG))&pico_socket_recv;
_pico_socket_open = (struct pico_socket*(*)(PICO_SOCKET_OPEN_SIG))&pico_socket_open; _pico_socket_open = (struct pico_socket*(*)(PICO_SOCKET_OPEN_SIG))&pico_socket_open;
_pico_socket_bind = (int(*)(PICO_SOCKET_BIND_SIG))&pico_socket_bind; _pico_socket_bind = (int(*)(PICO_SOCKET_BIND_SIG))&pico_socket_bind;
_pico_socket_connect = (int(*)(PICO_SOCKET_CONNECT_SIG))&pico_socket_connect; _pico_socket_connect = (int(*)(PICO_SOCKET_CONNECT_SIG))&pico_socket_connect;
@@ -188,6 +183,9 @@ namespace ZeroTier {
_pico_socket_close = (int(*)(PICO_SOCKET_CLOSE_SIG))&pico_socket_close; _pico_socket_close = (int(*)(PICO_SOCKET_CLOSE_SIG))&pico_socket_close;
_pico_socket_shutdown = (int(*)(PICO_SOCKET_SHUTDOWN_SIG))&pico_socket_shutdown; _pico_socket_shutdown = (int(*)(PICO_SOCKET_SHUTDOWN_SIG))&pico_socket_shutdown;
pico_socket_accept = (struct pico_socket*(*)(PICO_SOCKET_ACCEPT_SIG))&pico_socket_accept;
_pico_ipv6_link_add = (int(*)(PICO_IPV6_LINK_ADD_SIG))&pico_ipv6_link_add; _pico_ipv6_link_add = (int(*)(PICO_IPV6_LINK_ADD_SIG))&pico_ipv6_link_add;
_get_pico_err = (pico_err_t(*)())&get_pico_err; _get_pico_err = (pico_err_t(*)())&get_pico_err;
@@ -209,13 +207,11 @@ namespace ZeroTier {
_pico_device_init = (int(*)(PICO_DEVICE_INIT_SIG))dlsym(_libref, "pico_device_init"); _pico_device_init = (int(*)(PICO_DEVICE_INIT_SIG))dlsym(_libref, "pico_device_init");
_pico_stack_recv = (int32_t(*)(PICO_STACK_RECV_SIG))dlsym(_libref, "pico_stack_recv"); _pico_stack_recv = (int32_t(*)(PICO_STACK_RECV_SIG))dlsym(_libref, "pico_stack_recv");
_pico_icmp4_ping = (int(*)(PICO_ICMP4_PING_SIG))dlsym(_libref, "pico_icmp4_ping"); _pico_icmp4_ping = (int(*)(PICO_ICMP4_PING_SIG))dlsym(_libref, "pico_icmp4_ping");
_pico_string_to_ipv6 = (int(*)(PICO_STRING_TO_IPV6_SIG))dlsym(_libref, "pico_string_to_ipv6"); _pico_string_to_ipv6 = (int(*)(PICO_STRING_TO_IPV6_SIG))dlsym(_libref, "pico_string_to_ipv6");
_pico_socket_setoption = (int(*)(PICO_SOCKET_SETOPTION_SIG))dlsym(_libref, "pico_socket_setoption"); _pico_socket_setoption = (int(*)(PICO_SOCKET_SETOPTION_SIG))dlsym(_libref, "pico_socket_setoption");
_pico_timer_add = (uint32_t(*)(PICO_TIMER_ADD_SIG))dlsym(_libref, "pico_timer_add"); _pico_timer_add = (uint32_t(*)(PICO_TIMER_ADD_SIG))dlsym(_libref, "pico_timer_add");
_pico_socket_send = (int(*)(PICO_SOCKET_SEND_SIG))dlsym(_libref, "pico_socket_send"); _pico_socket_send = (int(*)(PICO_SOCKET_SEND_SIG))dlsym(_libref, "pico_socket_send");
_pico_socket_recv = (int(*)(PICO_SOCKET_RECV_SIG))dlsym(_libref, "pico_socket_recv"); _pico_socket_recv = (int(*)(PICO_SOCKET_RECV_SIG))dlsym(_libref, "pico_socket_recv");
_pico_socket_open = (struct pico_socket*(*)(PICO_SOCKET_OPEN_SIG))dlsym(_libref, "pico_socket_open"); _pico_socket_open = (struct pico_socket*(*)(PICO_SOCKET_OPEN_SIG))dlsym(_libref, "pico_socket_open");
_pico_socket_bind = (int(*)(PICO_SOCKET_BIND_SIG))dlsym(_libref, "pico_socket_bind"); _pico_socket_bind = (int(*)(PICO_SOCKET_BIND_SIG))dlsym(_libref, "pico_socket_bind");
_pico_socket_connect = (int(*)(PICO_SOCKET_CONNECT_SIG))dlsym(_libref, "pico_socket_connect"); _pico_socket_connect = (int(*)(PICO_SOCKET_CONNECT_SIG))dlsym(_libref, "pico_socket_connect");
@@ -224,7 +220,7 @@ namespace ZeroTier {
_pico_socket_write = (int(*)(PICO_SOCKET_WRITE_SIG))dlsym(_libref, "pico_socket_write"); _pico_socket_write = (int(*)(PICO_SOCKET_WRITE_SIG))dlsym(_libref, "pico_socket_write");
_pico_socket_close = (int(*)(PICO_SOCKET_CLOSE_SIG))dlsym(_libref, "pico_socket_close"); _pico_socket_close = (int(*)(PICO_SOCKET_CLOSE_SIG))dlsym(_libref, "pico_socket_close");
_pico_socket_shutdown = (int(*)(PICO_SOCKET_SHUTDOWN_SIG))dlsym(_libref, "pico_socket_shutdown"); _pico_socket_shutdown = (int(*)(PICO_SOCKET_SHUTDOWN_SIG))dlsym(_libref, "pico_socket_shutdown");
_pico_socket_accept = (struct pico_socket*(*)(PICO_SOCKET_ACCEPT_SIG))dlsym(_libref, "pico_socket_accept");
_pico_ipv6_link_add = (int(*)(PICO_IPV6_LINK_ADD_SIG))dlsym(_libref, "pico_ipv6_link_add"); _pico_ipv6_link_add = (int(*)(PICO_IPV6_LINK_ADD_SIG))dlsym(_libref, "pico_ipv6_link_add");
_get_pico_err = (pico_err_t(*)())dlsym(_libref, "get_pico_err"); _get_pico_err = (pico_err_t(*)())dlsym(_libref, "get_pico_err");
@@ -247,26 +243,22 @@ namespace ZeroTier {
inline int __pico_device_init(PICO_DEVICE_INIT_SIG) throw() { Mutex::Lock _l(_lock); return _pico_device_init(dev, name, mac); } inline int __pico_device_init(PICO_DEVICE_INIT_SIG) throw() { Mutex::Lock _l(_lock); return _pico_device_init(dev, name, mac); }
inline int __pico_stack_recv(PICO_STACK_RECV_SIG) throw() { /*Mutex::Lock _l(_lock);*/ return _pico_stack_recv(dev, buffer, len); } inline int __pico_stack_recv(PICO_STACK_RECV_SIG) throw() { /*Mutex::Lock _l(_lock);*/ return _pico_stack_recv(dev, buffer, len); }
inline int __pico_icmp4_ping(PICO_ICMP4_PING_SIG) throw() { Mutex::Lock _l(_lock); return _pico_icmp4_ping(dst, count, interval, timeout, size, cb); } inline int __pico_icmp4_ping(PICO_ICMP4_PING_SIG) throw() { Mutex::Lock _l(_lock); return _pico_icmp4_ping(dst, count, interval, timeout, size, cb); }
inline int __pico_string_to_ipv4(PICO_STRING_TO_IPV4_SIG) throw() { Mutex::Lock _l(_lock); return _pico_string_to_ipv4(ipstr, ip); } inline int __pico_string_to_ipv4(PICO_STRING_TO_IPV4_SIG) throw() { Mutex::Lock _l(_lock); return _pico_string_to_ipv4(ipstr, ip); }
inline int __pico_string_to_ipv6(PICO_STRING_TO_IPV6_SIG) throw() { Mutex::Lock _l(_lock); return _pico_string_to_ipv6(ipstr, ip); } inline int __pico_string_to_ipv6(PICO_STRING_TO_IPV6_SIG) throw() { Mutex::Lock _l(_lock); return _pico_string_to_ipv6(ipstr, ip); }
inline int __pico_socket_setoption(PICO_SOCKET_SETOPTION_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_setoption(s, option, value); } inline int __pico_socket_setoption(PICO_SOCKET_SETOPTION_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_setoption(s, option, value); }
inline uint32_t __pico_timer_add(PICO_TIMER_ADD_SIG) throw() { Mutex::Lock _l(_lock); return _pico_timer_add(expire, timer, arg); } inline uint32_t __pico_timer_add(PICO_TIMER_ADD_SIG) throw() { Mutex::Lock _l(_lock); return _pico_timer_add(expire, timer, arg); }
inline int __pico_socket_send(PICO_SOCKET_SEND_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_send(s, buf, len); } inline int __pico_socket_send(PICO_SOCKET_SEND_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_send(s, buf, len); }
inline int __pico_socket_recv(PICO_SOCKET_RECV_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_recv(s, buf, len); } inline int __pico_socket_recv(PICO_SOCKET_RECV_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_recv(s, buf, len); }
inline struct pico_socket * __pico_socket_open(PICO_SOCKET_OPEN_SIG) throw() { return _pico_socket_open(net, proto, wakeup); } inline struct pico_socket * __pico_socket_open(PICO_SOCKET_OPEN_SIG) throw() { return _pico_socket_open(net, proto, wakeup); }
inline int __pico_socket_bind(PICO_SOCKET_BIND_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_bind(s, local_addr, port); } inline int __pico_socket_bind(PICO_SOCKET_BIND_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_bind(s, local_addr, port); }
inline int __pico_socket_connect(PICO_SOCKET_CONNECT_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_connect(s, srv_addr, remote_port); } inline int __pico_socket_connect(PICO_SOCKET_CONNECT_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_connect(s, srv_addr, remote_port); }
inline int __pico_socket_listen(PICO_SOCKET_LISTEN_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_listen(s, backlog); } inline int __pico_socket_listen(PICO_SOCKET_LISTEN_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_listen(s, backlog); }
inline int __pico_socket_read(PICO_SOCKET_READ_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_read(s, buf, len); } inline int __pico_socket_read(PICO_SOCKET_READ_SIG) throw() { /*Mutex::Lock _l(_lock); */ return _pico_socket_read(s, buf, len); }
inline int __pico_socket_write(PICO_SOCKET_WRITE_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_write(s, buf, len); } inline int __pico_socket_write(PICO_SOCKET_WRITE_SIG) throw() { /*Mutex::Lock _l(_lock);*/ return _pico_socket_write(s, buf, len); }
inline int __pico_socket_close(PICO_SOCKET_CLOSE_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_close(s); } inline int __pico_socket_close(PICO_SOCKET_CLOSE_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_close(s); }
inline int __pico_socket_shutdown(PICO_SOCKET_SHUTDOWN_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_shutdown(s, mode); } inline int __pico_socket_shutdown(PICO_SOCKET_SHUTDOWN_SIG) throw() { Mutex::Lock _l(_lock); return _pico_socket_shutdown(s, mode); }
inline struct pico_socket * __pico_socket_accept(PICO_SOCKET_ACCEPT_SIG) throw() { /*Mutex::Lock _l(_lock);*/ return _pico_socket_accept(s, orig, port); }
inline int __pico_ipv6_link_add(PICO_IPV6_LINK_ADD_SIG) throw() { Mutex::Lock _l(_lock); return _pico_ipv6_link_add(dev, address, netmask); } inline int __pico_ipv6_link_add(PICO_IPV6_LINK_ADD_SIG) throw() { Mutex::Lock _l(_lock); return _pico_ipv6_link_add(dev, address, netmask); }
inline pico_err_t __get_pico_err(void) throw() { Mutex::Lock _l(_lock); return _get_pico_err(); } inline pico_err_t __get_pico_err(void) throw() { Mutex::Lock _l(_lock); return _get_pico_err(); }
}; };

View File

@@ -55,9 +55,11 @@ int main(int argc, char *argv[]) {
if (n < 0) if (n < 0)
error("ERROR writing to socket"); error("ERROR writing to socket");
printf("sent %d bytes\n", n);
memset(buffer, 0, 256); memset(buffer, 0, 256);
//Sockets Layer Call: recv() //Sockets Layer Call: recv()
printf("reading...\n");
n = recv(sockfd, buffer, 255, 0); n = recv(sockfd, buffer, 255, 0);
if (n < 0) if (n < 0)
error("ERROR reading from socket"); error("ERROR reading from socket");

View File

@@ -70,6 +70,7 @@ int main(int argc, char *argv[]) {
printf("Message from client: %s\n", buffer); printf("Message from client: %s\n", buffer);
//Sockets Layer Call: send() //Sockets Layer Call: send()
printf("sending...\n");
n = send(newsockfd, "Server got your message", 23+1, 0); n = send(newsockfd, "Server got your message", 23+1, 0);
if (n < 0) if (n < 0)
error("ERROR writing to socket"); error("ERROR writing to socket");