diff options
Diffstat (limited to 'server/tcp.h')
-rw-r--r-- | server/tcp.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/server/tcp.h b/server/tcp.h index e239e19..a393922 100644 --- a/server/tcp.h +++ b/server/tcp.h @@ -17,19 +17,60 @@ #define TCP_MAX_WAIT_MS 10 #define TCP_MAX_RETRIES 0 #define ADMIN_UID 0 +#define POLL_RESTART 5000 +struct channel_pool { + u64 id; + u64 owner; + int pipefd; + char *name; + u16 port; +}; + +/* Size: 4 + 4 + 8 + 8 + 32 + 4 + 8 = 68 bytes */ +/* I can't fucking count it's 64 bytes */ +struct connection_state { + // TODO: consider using clang extension to pack this enum into u8 + enum { + PROG_NONE = 0, // the socket has just been opened + // in loop: read type and continue + PROG_TYPE, // command type has been read + // in loop: start/continue reading command data + // when finished reading, set (& ~POLLIN) | POLLOUT + PROG_COMD, // command data has been read + // in loop: when revents & POLLOUT, write response + // or error, shutdown socket + PROG_ARRY, // extra data needs to be written + // (like in get_channels command) + PROG_ERRR, // an error happened and it should be reported, + // after that socket should be shut down and closed + } progress; + enum commd_type type; + u64 bytes_ctr; + u8 cmd_size; + struct commd cmd; + enum commd_error err; + union { + u64* response_array; + u64 response; + }; +}; /* val: struct tcp_channel */ extern struct hash_set channels; /* val: struct tcp_user */ extern struct hash_set users; +/* val: struct channel_pool*/ +extern struct hash_set pools; void print_state(int); void exit_tcp(int); void tcp_loop(void); +void new_tcp_loop(void); u64 spawn_channel(struct thread_loop_arg *arg); u64 spawn_channel_pool(void* arg); // TODO bool sendto_channel(size_t chid, struct kv_system_packet* packet, int wait_ack_ms, int repeat); #endif // KV_SERVER_TCP +/* vim: set ts=8 noet: */ |