Skip to content

Commit d8f2392

Browse files
committed
drivers, wiznet5k: Add socket_reset; fix orderly shutdown in recv.
1 parent 32ef3a3 commit d8f2392

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

drivers/wiznet5k/ethernet/socket.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
//! THE POSSIBILITY OF SUCH DAMAGE.
5050
//
5151
//*****************************************************************************
52+
53+
#include <string.h>
54+
5255
#include "socket.h"
5356

5457
extern void HAL_Delay(uint32_t);
@@ -85,7 +88,19 @@ static uint8_t sock_pack_info[_WIZCHIP_SOCK_NUM_] = {0,};
8588
if(len == 0) return SOCKERR_DATALEN; \
8689
}while(0); \
8790

91+
void WIZCHIP_EXPORT(socket_reset)(void) {
92+
sock_any_port = SOCK_ANY_PORT_NUM;
93+
sock_io_mode = 0;
94+
sock_is_sending = 0;
95+
/*
96+
memset(sock_remained_size, 0, _WIZCHIP_SOCK_NUM_ * sizeof(uint16_t));
97+
memset(sock_pack_info, 0, _WIZCHIP_SOCK_NUM_ * sizeof(uint8_t));
98+
*/
8899

100+
#if _WIZCHIP_ == 5200
101+
memset(sock_next_rd, 0, _WIZCHIP_SOCK_NUM_ * sizeof(uint16_t));
102+
#endif
103+
}
89104

90105
int8_t WIZCHIP_EXPORT(socket)(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
91106
{
@@ -336,8 +351,13 @@ int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len)
336351
if(recvsize != 0) break;
337352
else if(getSn_TX_FSR(sn) == getSn_TxMAX(sn))
338353
{
354+
// dpgeorge: Getting here seems to be an orderly shutdown of the
355+
// socket, and trying to get POSIX behaviour we return 0 because:
356+
// "If no messages are available to be received and the peer has per‐
357+
// formed an orderly shutdown, recv() shall return 0".
358+
// TODO this return value clashes with SOCK_BUSY in non-blocking mode.
339359
WIZCHIP_EXPORT(close)(sn);
340-
return SOCKERR_SOCKSTATUS;
360+
return 0;
341361
}
342362
}
343363
else

drivers/wiznet5k/ethernet/socket.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@
133133
#define PACK_REMAINED 0x01 ///< In Non-TCP packet, It indicates to remain a packet to be received.
134134
#define PACK_COMPLETED 0x00 ///< In Non-TCP packet, It indicates to complete to receive a packet.
135135

136+
// resets all global state associated with the socket interface
137+
void WIZCHIP_EXPORT(socket_reset)(void);
138+
136139
/**
137140
* @ingroup WIZnet_socket_APIs
138141
* @brief Open a socket.

drivers/wiznet5k/ethernet/wizchip_conf.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
//
5050

5151
#include "wizchip_conf.h"
52+
#include "socket.h"
53+
5254
/**
5355
* @brief Default function to enable interrupt.
5456
* @note This function help not to access wrong address. If you do not describe this function or register any functions,
@@ -328,6 +330,9 @@ int8_t wizchip_init(uint8_t* txsize, uint8_t* rxsize)
328330
for(i = 0 ; i < _WIZCHIP_SOCK_NUM_; i++)
329331
setSn_RXBUF_SIZE(i, rxsize[i]);
330332
}
333+
334+
WIZCHIP_EXPORT(socket_reset)();
335+
331336
return 0;
332337
}
333338

0 commit comments

Comments
 (0)