[lib][minip] add a timeout argument to tcp_accept()
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include <endian.h>
|
||||
#include <list.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <lib/pktbuf.h>
|
||||
|
||||
@@ -79,9 +80,14 @@ int minip_udp_listen(uint16_t port, udp_callback_t rx_handler, void *arg);
|
||||
typedef struct tcp_socket tcp_socket_t;
|
||||
|
||||
status_t tcp_open_listen(tcp_socket_t **handle, uint16_t port);
|
||||
status_t tcp_accept(tcp_socket_t *listen_socket, tcp_socket_t **accept_socket);
|
||||
status_t tcp_accept_timeout(tcp_socket_t *listen_socket, tcp_socket_t **accept_socket, lk_time_t timeout);
|
||||
status_t tcp_close(tcp_socket_t *socket);
|
||||
ssize_t tcp_read(tcp_socket_t *socket, void *buf, size_t len);
|
||||
ssize_t tcp_write(tcp_socket_t *socket, const void *buf, size_t len);
|
||||
|
||||
static inline status_t tcp_accept(tcp_socket_t *listen_socket, tcp_socket_t **accept_socket)
|
||||
{
|
||||
return tcp_accept_timeout(listen_socket, accept_socket, INFINITE_TIME);
|
||||
}
|
||||
|
||||
// vim: set ts=4 sw=4 expandtab:
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <lib/console.h>
|
||||
#include <lib/cbuf.h>
|
||||
#include <kernel/mutex.h>
|
||||
@@ -987,7 +988,7 @@ status_t tcp_open_listen(tcp_socket_t **handle, uint16_t port)
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
status_t tcp_accept(tcp_socket_t *listen_socket, tcp_socket_t **accept_socket)
|
||||
status_t tcp_accept_timeout(tcp_socket_t *listen_socket, tcp_socket_t **accept_socket, lk_time_t timeout)
|
||||
{
|
||||
if (!listen_socket || !accept_socket)
|
||||
return ERR_INVALID_ARGS;
|
||||
@@ -995,8 +996,11 @@ status_t tcp_accept(tcp_socket_t *listen_socket, tcp_socket_t **accept_socket)
|
||||
tcp_socket_t *s = listen_socket;
|
||||
inc_socket_ref(s);
|
||||
|
||||
/* block to accept a socket */
|
||||
sem_wait(&s->accept_sem);
|
||||
/* block to accept a socket for an amount of time */
|
||||
if (sem_timedwait(&s->accept_sem, timeout) == ERR_TIMED_OUT) {
|
||||
dec_socket_ref(s);
|
||||
return ERR_TIMED_OUT;
|
||||
}
|
||||
|
||||
mutex_acquire(&s->lock);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user