commit 48f7999db0df1a8a05ab3d70fb62348b056b0dd7
parent eb0cafd4de462ce37f8cc17b0936ecb7b5234393
Author: Yersa Nordman <yersa@finwo.nl>
Date: Mon, 24 Jul 2023 02:16:09 +0200
Argument presence checking in fnet_listen
Diffstat:
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/src/fnet.c b/src/fnet.c
@@ -2,6 +2,7 @@
extern "C" {
#endif
+#include <stdio.h>
#include <stdlib.h>
#include "tidwall/buf.h"
@@ -10,13 +11,43 @@ extern "C" {
struct fnet_internal_t {
struct fnet_t ext; // KEEP AT TOP, allows casting between fnet_internal_t* and fnet_t*
+ FNET_SOCKET sock;
+ FNET_FLAG flags;
+ FNET_CALLBACK(onConnect);
+ FNET_CALLBACK_VA(onData, struct buf *data);
+ FNET_CALLBACK(onClose);
};
struct fnet_t * fnet_listen(const char *address, uint16_t port, struct fnet_connect_options_t *options) {
+
+ // Checking arguments are given
+ if (!address) {
+ fprintf(stderr, "fnet_listen: address argument is required\n");
+ return NULL;
+ }
+ if (!port) {
+ fprintf(stderr, "fnet_listen: port argument is required\n");
+ return NULL;
+ }
+ if (!options) {
+ fprintf(stderr, "fnet_listen: options argument is required\n");
+ return NULL;
+ }
+
+ // Check if we support the protocol
+ switch(options->proto) {
+ case FNET_PROTO_TCP:
+ // TODO: something
+ break;
+ default:
+ fprintf(stderr, "fnet_listen: unknown protocol\n");
+ return NULL;
+ }
+
return NULL;
}
-struct fnet_t * fnet_connect(const char *address, uint16_t port, struct fnet_connect_options_t *options) {
+struct fnet_t * fnet_connect(const char *address, struct fnet_connect_options_t *options) {
return NULL;
}
diff --git a/src/fnet.h b/src/fnet.h
@@ -27,13 +27,8 @@ extern "C" {
#define FNET_CALLBACK_VA(NAME, ...) void (*(NAME))(struct fnet_t *connection, __VA_ARGS__, void *udata)
struct fnet_t {
- FNET_SOCKET sock;
FNET_PROTOCOL proto;
FNET_STATUS status;
- FNET_FLAG flags;
- FNET_CALLBACK(onConnect);
- FNET_CALLBACK_VA(onData, struct buf *data);
- FNET_CALLBACK(onClose);
void *udata;
};
@@ -47,7 +42,7 @@ struct fnet_connect_options_t {
};
struct fnet_t * fnet_listen(const char *address, uint16_t port, struct fnet_connect_options_t *options);
-struct fnet_t * fnet_connect(const char *address, uint16_t port, struct fnet_connect_options_t *options);
+struct fnet_t * fnet_connect(const char *address, struct fnet_connect_options_t *options);
void fnet_process(struct fnet_t *connection);
void fnet_write(struct fnet_t *connection, struct buf *buf);