Skip to content

Commit

Permalink
tcp-chnl: add TCP connection established callback for connect and accept
Browse files Browse the repository at this point in the history
The commit adds calls the TCP connection callback for clients when they
establish a connection i.e. the connection is ready to send and receive
data.

To simplify things, `CHNL_TCP_ACCEPT_TYPE` is renamed to
`CHNL_TCP_ESTABLISHED_TYPE`. The callback type is used for both
server's `accept` and client's `connect`. In case of accept, the
listening channel descriptor is passed to the callback. In case of
connect, the client channel descriptor is passed.

Signed-off-by: Jalal Mostafa <[email protected]>
  • Loading branch information
jalalmostafa authored and KeithWiles committed Jun 20, 2024
1 parent aeb5b8f commit 75ba078
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
14 changes: 7 additions & 7 deletions doc/guides/sample_app_ug/cnet_graph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ The channel callback types are shown below:
.. code-block:: c
/** Channel callback types */
typedef enum {
CHNL_UDP_RECV_TYPE, /**< Callback for receiving UDP packets */
CHNL_UDP_CLOSE_TYPE, /**< Callback for UDP close */
CHNL_TCP_ACCEPT_TYPE, /**< Callback type for accepting TCP connection */
CHNL_TCP_RECV_TYPE, /**< Callback for receiving TCP packets */
CHNL_TCP_CLOSE_TYPE, /**< Callback for TCP close */
CHNL_CALLBACK_TYPES /**< Maximum number of callback types */
typedef enum {
CHNL_UDP_RECV_TYPE, /**< Callback for receiving UDP packets */
CHNL_UDP_CLOSE_TYPE, /**< Callback for UDP close */
CHNL_TCP_ESTABLISHED_TYPE, /**< Callback for when TCP is established: `accept` or `connect` */
CHNL_TCP_RECV_TYPE, /**< Callback for receiving TCP packets */
CHNL_TCP_CLOSE_TYPE, /**< Callback for TCP close */
CHNL_CALLBACK_TYPES /**< Maximum number of callback types */
} chnl_type_t;
Packet Forwarding using Graph Walk
Expand Down
12 changes: 6 additions & 6 deletions lib/cnet/chnl/cnet_chnl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ enum {

/** Channel callback types */
typedef enum {
CHNL_UDP_RECV_TYPE, /**< Callback for receiving UDP packets */
CHNL_UDP_CLOSE_TYPE, /**< Callback for UDP close */
CHNL_TCP_ACCEPT_TYPE, /**< Callback type for accepting TCP connection */
CHNL_TCP_RECV_TYPE, /**< Callback for receiving TCP packets */
CHNL_TCP_CLOSE_TYPE, /**< Callback for TCP close */
CHNL_CALLBACK_TYPES /**< Maximum number of callback types */
CHNL_UDP_RECV_TYPE, /**< Callback for receiving UDP packets */
CHNL_UDP_CLOSE_TYPE, /**< Callback for UDP close */
CHNL_TCP_ESTABLISHED_TYPE, /**< Callback for when TCP is established: `accept` or `connect` */
CHNL_TCP_RECV_TYPE, /**< Callback for receiving TCP packets */
CHNL_TCP_CLOSE_TYPE, /**< Callback for TCP close */
CHNL_CALLBACK_TYPES /**< Maximum number of callback types */
} chnl_type_t;

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/cnet/tcp/cnet_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,8 +1389,10 @@ tcp_do_state_change(struct pcb_entry *pcb, int32_t new_state)
cnet_tcp_abort(pcb);
CNE_ERR("Failed to enqueue PCB to backlog queue\n");
}
pcb->ch->ch_callback(CHNL_TCP_ACCEPT_TYPE, tcb->ppcb->ch->ch_cd);
pcb->ch->ch_callback(CHNL_TCP_ESTABLISHED_TYPE, tcb->ppcb->ch->ch_cd);
}
} else {
pcb->ch->ch_callback(CHNL_TCP_ESTABLISHED_TYPE, pcb->ch->ch_cd);
}

tcb->idle = 0;
Expand Down

0 comments on commit 75ba078

Please sign in to comment.