- TCP: set_accept_cb() added; semaphore release bugs fixed
This commit is contained in:
parent
cea600b3a4
commit
ca97d1718a
@ -3,16 +3,16 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../packet_parsers/packet_parsers.h"
|
||||
#include "../../utils.h"
|
||||
#include "../../dynmem.h"
|
||||
#include "../../pckt_assembler.h"
|
||||
#include "../../eth_interface.h"
|
||||
#include "ipv4_connblock.h"
|
||||
#include "../../gen_queue.h"
|
||||
#include "etherlib_options.h"
|
||||
#include "../../prefab/conn_blocks/tcp/tcp_window.h"
|
||||
#include "../../global_state.h"
|
||||
#include "../../pckt_assembler.h"
|
||||
#include "../../prefab/conn_blocks/tcp/tcp_window.h"
|
||||
#include "../../utils.h"
|
||||
#include "../packet_parsers/packet_parsers.h"
|
||||
#include "etherlib_options.h"
|
||||
#include "ipv4_connblock.h"
|
||||
|
||||
// TODO: - retransmission hiányzik
|
||||
// TODO: - állapotváltás esetleg a küldés előtt? (külcsönös kizárás és társai...)
|
||||
@ -30,8 +30,7 @@ static inline cbd tcp_new_connblock_filtcond(EthInterface *intf, ip4_addr ipAddr
|
||||
|
||||
static char *TCP_STATE_NAMES[] = {
|
||||
"CLOSED", "LISTEN", "SYN_RCVD", "SYN_SENT", "ESTAB", "FIN_WAIT_1",
|
||||
"FIN_WAIT_2", "CLOSE_WAIT", "CLOSING", "LAST_ACK", "TIME_WAIT"
|
||||
};
|
||||
"FIN_WAIT_2", "CLOSE_WAIT", "CLOSING", "LAST_ACK", "TIME_WAIT"};
|
||||
|
||||
int tcp_send_segment(const struct ConnBlock_ *connBlock, TcpFlag flags, TcpOption *opts, const uint8_t *data, uint32_t size);
|
||||
|
||||
@ -56,7 +55,9 @@ static inline TcpState *tcps_create() {
|
||||
uint32_t winSize = MAX(ETHLIB_DEF_TCP_WINDOW_SIZE, MAX_TCP_WINDOW_SIZE);
|
||||
tcps->txWin = tcpw_create(winSize); // create transmit window
|
||||
tcps->txBufNotFull = ETHLIB_OS_SEM_CREATE(1); // create transmit buffer not full semaphore
|
||||
ETHLIB_OS_SEM_POST(tcps->txBufNotFull); // post the tx buffer semaphore
|
||||
tcps->txInProgress = ETHLIB_OS_SEM_CREATE(1); // create transmission in progress semaphore
|
||||
ETHLIB_OS_SEM_POST(tcps->txInProgress);
|
||||
|
||||
return tcps;
|
||||
}
|
||||
@ -205,7 +206,6 @@ int tcp_receive_segment_cb(const Pckt *pckt, PcktSieveLayerTag tag) {
|
||||
// step into next state
|
||||
tcps->connState = TCP_STATE_ESTAB;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
@ -245,7 +245,6 @@ int tcp_receive_segment_cb(const Pckt *pckt, PcktSieveLayerTag tag) {
|
||||
tcps->acceptCb(client_d);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
@ -297,8 +296,8 @@ int tcp_receive_segment_cb(const Pckt *pckt, PcktSieveLayerTag tag) {
|
||||
case TCP_STATE_LAST_ACK: /* last ACK received */
|
||||
if (tcpProps->Flags & TCP_FLAG_ACK) {
|
||||
tcps->connState = TCP_STATE_CLOSED;
|
||||
ETHLIB_OS_SEM_POST(tcps->txBufNotFull);
|
||||
ETHLIB_OS_SEM_WAIT(tcps->txInProgress);
|
||||
//ETHLIB_OS_SEM_POST(tcps->txBufNotFull); FIXME!
|
||||
//ETHLIB_OS_SEM_WAIT(tcps->txInProgress);
|
||||
ret = SIEVE_LAYER_REMOVE_THIS; // if peer closed the connection, remove sieve layer
|
||||
}
|
||||
break;
|
||||
@ -377,6 +376,17 @@ void tcp_listen(cbd d) {
|
||||
}
|
||||
}
|
||||
|
||||
void tcp_set_accept_callback(cbd d, TcpAcceptCbFn acb) {
|
||||
ConnBlock connBlock;
|
||||
if (!cbdt_get_connection_block(E.cbdt, d, &connBlock)) {
|
||||
ERROR("Invalid CBD descriptor: '%d'!\n", d);
|
||||
return;
|
||||
}
|
||||
|
||||
TcpState *tcps = TCP_FETCH_STATE_FROM_CONNBLOCK(&connBlock);
|
||||
tcps->acceptCb = acb;
|
||||
}
|
||||
|
||||
void tcp_debug(cbd d, bool debug) {
|
||||
ConnBlock connBlock;
|
||||
if (!cbdt_get_connection_block(E.cbdt, d, &connBlock)) {
|
||||
|
@ -103,7 +103,7 @@ typedef struct {
|
||||
|
||||
// ---------------
|
||||
|
||||
BlockingFifo * rxFifo; ///< Receive FIFO
|
||||
EthBlockingFifo * rxFifo; ///< Receive FIFO
|
||||
|
||||
} TcpState;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user