further picotcp api coverage
This commit is contained in:
@@ -165,16 +165,27 @@ PICO_TREE_DECLARE(TCPTable, sockport_cmp);
|
||||
|
||||
struct pico_sockport *pico_get_sockport(uint16_t proto, uint16_t port)
|
||||
{
|
||||
printf("pico_get_sockport\n");
|
||||
struct pico_sockport test = INIT_SOCKPORT;
|
||||
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);
|
||||
}
|
||||
|
||||
else if (proto == PICO_PROTO_TCP){
|
||||
printf("pico_get_sockport: proto TCP?\n");
|
||||
|
||||
else if (proto == PICO_PROTO_TCP)
|
||||
return pico_tree_findKey(&TCPTable, &test);
|
||||
}
|
||||
|
||||
else return NULL;
|
||||
else
|
||||
{
|
||||
printf("pico_get_sockport: proto NULL?\n");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PICO_SUPPORT_IPV4
|
||||
@@ -324,6 +335,7 @@ int pico_is_port_free(uint16_t proto, uint16_t port, void *addr, void *net)
|
||||
|
||||
static int pico_check_socket(struct pico_socket *s)
|
||||
{
|
||||
printf("pico_check_socket\n");
|
||||
struct pico_sockport *test;
|
||||
struct pico_socket *found;
|
||||
struct pico_tree_node *index;
|
||||
@@ -331,6 +343,8 @@ static int pico_check_socket(struct pico_socket *s)
|
||||
test = pico_get_sockport(PROTO(s), s->local_port);
|
||||
|
||||
if (!test) {
|
||||
printf("!test\n");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -341,6 +355,8 @@ static int pico_check_socket(struct pico_socket *s)
|
||||
}
|
||||
}
|
||||
|
||||
printf("no key found\n");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -686,6 +702,7 @@ static int pico_socket_transport_read(struct pico_socket *s, void *buf, int len)
|
||||
return pico_socket_tcp_read(s, buf, (uint32_t)len);
|
||||
else return 0;
|
||||
}
|
||||
#include <stdio.h>
|
||||
|
||||
int pico_socket_read(struct pico_socket *s, void *buf, int len)
|
||||
{
|
||||
@@ -711,17 +728,25 @@ int pico_socket_read(struct pico_socket *s, void *buf, int len)
|
||||
|
||||
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) {
|
||||
printf("PICO_ERR_EIO\n");
|
||||
|
||||
pico_err = PICO_ERR_EIO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((s->state & PICO_SOCKET_STATE_CONNECTED) == 0) {
|
||||
printf("PICO_ERR_ENOTCONN\n");
|
||||
|
||||
pico_err = PICO_ERR_ENOTCONN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (s->state & PICO_SOCKET_STATE_SHUT_LOCAL) { /* check if in shutdown state */
|
||||
printf("PICO_ERR_ESHUTDOWN\n");
|
||||
|
||||
pico_err = PICO_ERR_ESHUTDOWN;
|
||||
return -1;
|
||||
}
|
||||
@@ -731,7 +756,11 @@ 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)
|
||||
{
|
||||
printf("pico_socket_write_attempt\n");
|
||||
|
||||
if (pico_socket_write_check_state(s) < 0) {
|
||||
printf("pico_socket_write_check_state = -1\n");
|
||||
|
||||
return -1;
|
||||
} else {
|
||||
return pico_socket_sendto(s, buf, len, &s->remote_addr, s->remote_port);
|
||||
@@ -740,13 +769,18 @@ 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)
|
||||
{
|
||||
printf("pico_socket_write\n");
|
||||
if (!s || buf == NULL) {
|
||||
printf("PICO_ERR_EINVAL\n");
|
||||
|
||||
pico_err = PICO_ERR_EINVAL;
|
||||
return -1;
|
||||
} else {
|
||||
/* check if exists in tree */
|
||||
/* See task #178 */
|
||||
if (pico_check_socket(s) != 0) {
|
||||
printf("PICO_ERR_EINVAL?\n");
|
||||
|
||||
pico_err = PICO_ERR_EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user