commit 11df440e30877f8381f9284289dcf4b753e2f800
parent f8f04bd973c52748e7cd9eaa8076d265d671fbdd
Author: Yersa Nordman <yersa@finwo.nl>
Date: Wed, 2 Aug 2023 00:16:06 +0200
Allow user of lib to detect if the connection was accepted or connected
Diffstat:
3 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/fnet.c b/src/fnet.c
@@ -253,9 +253,9 @@ FNET_RETURNCODE fnet_process(const struct fnet_t *connection) {
}
// No processing to be done here
- if (conn->ext.status == FNET_STATUS_INITIALIZING) return FNET_RETURNCODE_OK;
- if (conn->ext.status & FNET_STATUS_ERROR ) return FNET_RETURNCODE_OK;
- if (conn->ext.status & FNET_STATUS_CLOSED ) return FNET_RETURNCODE_OK;
+ if (conn->ext.status & FNET_STATUS_INITIALIZING) return FNET_RETURNCODE_OK;
+ if (conn->ext.status & FNET_STATUS_ERROR ) return FNET_RETURNCODE_OK;
+ if (conn->ext.status & FNET_STATUS_CLOSED ) return FNET_RETURNCODE_OK;
/* // Handle client still connecting */
/* if (conn->ext.status & FNET_STATUS_CONNECTING) { */
@@ -330,7 +330,7 @@ FNET_RETURNCODE fnet_process(const struct fnet_t *connection) {
nconn->fds = malloc(sizeof(FNET_SOCKET));
nconn->fds[0] = nfd;
nconn->nfds = 1;
- nconn->ext.status = FNET_STATUS_CONNECTED;
+ nconn->ext.status = FNET_STATUS_CONNECTED | FNET_STATUS_ACCEPTED;
if (conn->ext.onConnect) {
conn->ext.onConnect(&((struct fnet_ev){
diff --git a/src/fnet.h b/src/fnet.h
@@ -26,11 +26,12 @@ extern "C" {
#define FNET_STATUS uint8_t
#define FNET_STATUS_INITIALIZING 0
#define FNET_STATUS_CONNECTING 1 // Client-only status
-#define FNET_STATUS_CONNECTED 2 // Client ready
+#define FNET_STATUS_CONNECTED 2 // Connection ready
#define FNET_STATUS_LISTENING 4 // Listen ready
#define FNET_STATUS_READY 6 // Any ready
-#define FNET_STATUS_ERROR 8
-#define FNET_STATUS_CLOSED 16
+#define FNET_STATUS_ACCEPTED 8 // Whether the connection is an accepted one
+#define FNET_STATUS_ERROR 16
+#define FNET_STATUS_CLOSED 32
#define FNET_EVENT int
#define FNET_EVENT_CONNECT 1
diff --git a/test.c b/test.c
@@ -95,7 +95,7 @@ int main(int argc, const char *argv[]) {
.onData = NULL,
.onTick = onTick,
.onClose = NULL,
- .udata = &mode,
+ .udata = NULL,
};
fnet_listen(addr, port, &opts);
fnet_main();