aboutsummaryrefslogtreecommitdiffstats
path: root/test/general.c
diff options
context:
space:
mode:
authorjustanothercatgirl <sotov@twistea.su>2025-02-08 22:13:52 +0300
committerjustanothercatgirl <sotov@twistea.su>2025-02-08 22:13:52 +0300
commitcab382db088d9f240253466a1c5a26c62f3967c8 (patch)
treec5502f1b49211dccd3e29e163e708708495a6407 /test/general.c
parent3eeee14d5d5c93ae3d156aabae5a96d1c09f185a (diff)
Implemented multiplexing in main thread (TCP loop). Removed CMake files.HEADmaster
TODO: Implement multiplexing in worker threads (UDP loops), implement channel_pool interface.
Diffstat (limited to 'test/general.c')
-rw-r--r--test/general.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/test/general.c b/test/general.c
index d7673a3..95109a3 100644
--- a/test/general.c
+++ b/test/general.c
@@ -6,6 +6,7 @@
#include <errno.h>
#include <packet.h>
+#include <log.h>
#define W printf("LINE %i\n", __LINE__)
@@ -14,7 +15,7 @@ enum commd_error cerr;
void setup_globals(void) { commsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); }
-u64 sendtoserv(int sock, enum commd_type t, struct commd *cmd, enum commd_error * NULLABLE e) {
+u64 sendtoserv(int sock, enum commd_type t, struct commd *cmd, enum commd_error * NULLABLE e) {
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
struct sockaddr_in serv = {
.sin_family = AF_INET, .sin_port = htons(TCP_PORT), .sin_addr = {htonl(INADDR_LOOPBACK)}};
@@ -37,43 +38,50 @@ u64 sendtoserv(int sock, enum commd_type t, struct commd *cmd, enum commd_error
u64 register_user(i32 perm) {
struct commd_register r = {.auid = hton64(0), .perm = hton64(perm)};
- if (cerr != ERR_SUCCESS) DEBUGF("Server returned error %i: %s. errno: %s\n", cerr, kv_strerror(cerr), strerror(errno));
return sendtoserv(commsock, CMD_REGISTER, (struct commd *)&r, &cerr);
+ if (cerr != ERR_SUCCESS) LDEBUGF("Server returned error %i: %s. errno: %s\n", cerr, kv_strerror(cerr), strerror(errno));
}
void unreg_user(u64 u) {
struct commd_unregister unreg = {.auid = hton64(u), .uid = hton64(u)};
u64 resp = sendtoserv(commsock, CMD_UNREGISTER, (struct commd *)&unreg, &cerr);
- if (cerr != ERR_SUCCESS) DEBUGF("Server returned error %i: %s. errno: %s\n", cerr, kv_strerror(cerr), strerror(errno));
+ if (cerr != ERR_SUCCESS) LDEBUGF("Server returned error %i: %s. errno: %s\n", cerr, kv_strerror(cerr), strerror(errno));
printf("sendtoserv returned %zu\n", resp);
}
u64 create_channel(u64 u) {
struct commd_create c = {.uid = hton64(u)};
u64 resp = sendtoserv(commsock, CMD_CREATE, (struct commd *)&c, &cerr);
- if (cerr != ERR_SUCCESS) DEBUGF("Server returned error %i: %s\n", cerr, kv_strerror(cerr));
+ if (cerr != ERR_SUCCESS) LDEBUGF("Server returned error %i: %s\n", cerr, kv_strerror(cerr));
return resp;
}
void* thr(void* a) {
(void)a;
- u64 uid = register_user(perm_none);
+ u64 uid = register_user(PERM_NONE);
printf("uid: %zu\n", uid);
unreg_user(uid);
- uid = register_user(perm_admin);
+ uid = register_user(PERM_ADMIN);
printf("uid: %zu\n", uid);
u64 chid = create_channel(uid);
printf("chid: %zu\n", chid);
return NULL;
}
+#ifndef n
+# define n 3
+#endif
+
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
- for (int i = 0; i < 1; ++i) {
- pthread_t t;
- pthread_create(&t, NULL, thr, NULL);
+ pthread_t ts[n];
+ for (int i = 0; i < n; ++i) {
+ pthread_create(ts + i, NULL, thr, NULL);
}
+ for (int i = 0; i < n; ++i)
+ pthread_join(ts[i], NULL);
sleep(1);
return 0;
}
+/* vim: set ts=8 noet: */