the juciest squids you will ever see
This commit is contained in:
parent
f1dd4943ae
commit
e3171c9494
12 changed files with 159 additions and 72 deletions
BIN
core
BIN
core
Binary file not shown.
75
protocol
75
protocol
|
@ -23,29 +23,72 @@ byte the bytes after the header octet bytes bytes:
|
||||||
---
|
---
|
||||||
|
|
||||||
client -> server
|
client -> server
|
||||||
id 0: registration attempt
|
id 0: clerical request
|
||||||
r.0 - username - string (max 9b)
|
r.0 - clerical id - byte
|
||||||
r.1 - pin - ushort (max 9999)
|
|
||||||
|
|
||||||
id 1: login attempt
|
id 1: alert prompt response
|
||||||
r.0 - username - string (max 9b)
|
r.0 - clerical id - byte
|
||||||
r.1 - pin - ushort (max 9999)
|
r.1 - prompt id - byte
|
||||||
|
|
||||||
id 2: ctx change response
|
id 2: boolean prompt response
|
||||||
|
r.0 - clerical id - byte
|
||||||
|
r.1 - prompt id - byte
|
||||||
|
r.2 - response - bool
|
||||||
|
|
||||||
|
id 3: string prompt response
|
||||||
|
r.0 - clerical id - byte
|
||||||
|
r.1 - prompt id - byte
|
||||||
|
r.2 - response - string (256b)
|
||||||
|
|
||||||
|
id 4: list prompt response
|
||||||
|
r.0 - clerical id - byte
|
||||||
|
r.1 - prompt id - byte
|
||||||
|
r.2 - response - ushort
|
||||||
|
|
||||||
|
id 5: ctx change response
|
||||||
r.0 - ack - bool
|
r.0 - ack - bool
|
||||||
r.1 - ctx id - ushort
|
r.1 - ctx id - ushort
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
server -> client
|
server -> client
|
||||||
id 0: registration response
|
id 0: clerical response
|
||||||
r.0 - succeeded - bool
|
r.0 - clerical id - byte
|
||||||
r.1 - status - string (17b)
|
r.1 - success - bool
|
||||||
|
|
||||||
id 1: login response
|
id 1: alert prompt
|
||||||
r.0 - succeeded - bool
|
r.0 - clerical id - byte
|
||||||
r.1 - user id - ushort
|
r.1 - prompt id - byte
|
||||||
r.2 - status - string (17b)
|
r.2 - prompt width - ushort
|
||||||
|
r.3 - text - string (512b)
|
||||||
|
|
||||||
|
id 2: boolean prompt
|
||||||
|
r.0 - clerical id - byte
|
||||||
|
r.1 - prompt id - byte
|
||||||
|
r.2 - prompt width - ushort
|
||||||
|
r.3 - text - string (512b)
|
||||||
|
|
||||||
|
id 3: string prompt
|
||||||
|
r.0 - clerical id - byte
|
||||||
|
r.1 - prompt id - byte
|
||||||
|
r.2 - prompt width - ushort
|
||||||
|
r.3 - text - string (512b)
|
||||||
|
r.4 - strlen - byte
|
||||||
|
|
||||||
|
id 4: list prompt
|
||||||
|
r.0 - clerical id - byte
|
||||||
|
r.1 - prompt id - byte
|
||||||
|
r.2 - prompt width - ushort
|
||||||
|
r.3 - text - string (512b)
|
||||||
|
r.4 - option count - n - ushort
|
||||||
|
r.x | 4 < x <= 4+n
|
||||||
|
- option text - string (256b)
|
||||||
|
|
||||||
id 2: ctx change request
|
id 5: ctx change request
|
||||||
r.0 - ctx id - ushort
|
r.0 - ctx id - ushort
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
CLERICAL IDs
|
||||||
|
id 0: register
|
||||||
|
id 1: login
|
|
@ -116,8 +116,8 @@ static int main_menu() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
attron(color);
|
attron(color);
|
||||||
mvprintw(AFTER_BANNER + 3 + i*2, (COLS - (MM_MAX_OPT_LEN + 2)) / 2,
|
mvprintw(AFTER_BANNER + 3 + i*2, (COLS - (MM_MAX_OPT_LEN + 3)) / 2,
|
||||||
"* %s", MM_OPTIONS[i]);
|
"%s %s", selected == i ? "->" : " *", MM_OPTIONS[i]);
|
||||||
attroff(color);
|
attroff(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,9 +155,21 @@ void how_to_play() {
|
||||||
|
|
||||||
void create_account() {
|
void create_account() {
|
||||||
|
|
||||||
char input[9];
|
int len;
|
||||||
scr_prompt_string(20, "this prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test", input, 8);
|
packet_t *pck = packet_init_out(0, 0);
|
||||||
|
packet_append_uint8(pck, PCK_CLERIC_REG);
|
||||||
|
uint8_t *out = packet_get_raw(pck, &len);
|
||||||
|
|
||||||
|
sock_send(ctx.sock, out, len);
|
||||||
|
|
||||||
|
packet_free(pck);
|
||||||
|
|
||||||
|
char input[9];
|
||||||
|
//scr_prompt_string(20, "this prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test of a prompt box is a test", input, 8);
|
||||||
|
|
||||||
|
scr_prompt_voptions(40, "test of a prompt box of a prompt box of a prompt box of a prompt\n \nbox of a prompt box of a prompt box\n \nthis is a test of a prompt box", 3,
|
||||||
|
"testtesttesttesttesttesttest a", "test b", "test c");
|
||||||
|
|
||||||
/*int a = 0;
|
/*int a = 0;
|
||||||
while(a != KEY_LF)
|
while(a != KEY_LF)
|
||||||
printw("%i ", (a = getch()));*/
|
printw("%i ", (a = getch()));*/
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
|
#include "packet.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
|
|
|
@ -73,28 +73,28 @@ WINDOW* scr_win_box(int top, int left, int width, int height) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int calculate_height(int width, char *text) {
|
static int calculate_height(int width, char *text) {
|
||||||
int len = strlen(text), lines = 0, line_width, line_len, char_width, i;
|
int len = strlen(text), lines = 0, char_width = 0,
|
||||||
|
line_len, line_width, i;
|
||||||
char *ptr, *cpy = (char*)malloc(len * sizeof(char));
|
char *ptr, *cpy = (char*)malloc(len * sizeof(char));
|
||||||
strcpy(cpy, text);
|
strcpy(cpy, text);
|
||||||
|
|
||||||
ptr = strtok(cpy, "\n");
|
ptr = strtok(cpy, "\n");
|
||||||
while(ptr != NULL) {
|
while(ptr != NULL) {
|
||||||
line_width = 0;
|
line_width = 0;
|
||||||
line_len = strlen(ptr);
|
for(i = 0; ptr[i] != '\0'; ++i) {
|
||||||
for(i = 0; i < line_len; ++i) {
|
if((ptr[i] & 0x80) == 0 && isprint(ptr[i])) {
|
||||||
if(ptr[i] & 0x80 == 0 && isprint(ptr[i])) {
|
|
||||||
char_width = 0;
|
char_width = 0;
|
||||||
++line_width;
|
++line_width;
|
||||||
} else if(ptr[i] & 0xE0 == 0xC0) {
|
} else if((ptr[i] & 0xE0) == 0xC0) {
|
||||||
char_width = 1;
|
char_width = 1;
|
||||||
++line_width;
|
++line_width;
|
||||||
} else if(ptr[i] & 0xF0 == 0xE0) {
|
} else if((ptr[i] & 0xF0) == 0xE0) {
|
||||||
char_width = 2;
|
char_width = 2;
|
||||||
++line_width;
|
++line_width;
|
||||||
} else if(ptr[i] & 0xF8 == 0xF0) {
|
} else if((ptr[i] & 0xF8) == 0xF0) {
|
||||||
char_width = 3;
|
char_width = 3;
|
||||||
++line_width;
|
++line_width;
|
||||||
} else if(ptr[i] & 0xC0 == 0x80) {
|
} else if((ptr[i] & 0xC0) == 0x80) {
|
||||||
if(char_width > 0)
|
if(char_width > 0)
|
||||||
--char_width;
|
--char_width;
|
||||||
else
|
else
|
||||||
|
@ -102,11 +102,11 @@ static int calculate_height(int width, char *text) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lines += MAX(1, (int)ceil((float)line_width / width));
|
||||||
|
|
||||||
ptr = strtok(NULL, "\n");
|
ptr = strtok(NULL, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(cpy);
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ void scr_alert(int width, char *text) {
|
||||||
|
|
||||||
short pair;
|
short pair;
|
||||||
WINDOW *win;
|
WINDOW *win;
|
||||||
int text_height = calculate_height(width, strlen(text));
|
int text_height = calculate_height(width, text);
|
||||||
|
|
||||||
#ifdef WORK
|
#ifdef WORK
|
||||||
pair = SCR_PAIR(SCR_WHITE, SCR_BLACK);
|
pair = SCR_PAIR(SCR_WHITE, SCR_BLACK);
|
||||||
|
@ -158,7 +158,7 @@ BOOL scr_prompt(int width, char *text) {
|
||||||
char check[] = "[ \u2714 ]";
|
char check[] = "[ \u2714 ]";
|
||||||
char cross[] = "[ \u2718 ]";
|
char cross[] = "[ \u2718 ]";
|
||||||
WINDOW *win;
|
WINDOW *win;
|
||||||
int text_height = calculate_height(width, strlen(text));
|
int text_height = calculate_height(width, text);
|
||||||
|
|
||||||
#ifdef WORK
|
#ifdef WORK
|
||||||
pair = SCR_PAIR(SCR_WHITE, SCR_BLACK);
|
pair = SCR_PAIR(SCR_WHITE, SCR_BLACK);
|
||||||
|
@ -230,7 +230,7 @@ void scr_prompt_string(int width, char *text, char *out, int outlen) {
|
||||||
int ch, curlen = 0, i, origin;
|
int ch, curlen = 0, i, origin;
|
||||||
short pair;
|
short pair;
|
||||||
WINDOW *win;
|
WINDOW *win;
|
||||||
int text_height = calculate_height(width, strlen(text));
|
int text_height = calculate_height(width, text);
|
||||||
|
|
||||||
#ifdef WORK
|
#ifdef WORK
|
||||||
pair = SCR_PAIR(SCR_WHITE, SCR_BLACK);
|
pair = SCR_PAIR(SCR_WHITE, SCR_BLACK);
|
||||||
|
@ -268,10 +268,10 @@ void scr_prompt_string(int width, char *text, char *out, int outlen) {
|
||||||
wattroff(win, A_UNDERLINE);
|
wattroff(win, A_UNDERLINE);
|
||||||
wattroff(win, pair);
|
wattroff(win, pair);
|
||||||
|
|
||||||
//if(curlen < outlen)
|
if(curlen < outlen)
|
||||||
wmove(win, text_height + 1, origin + 3 + curlen);
|
wmove(win, text_height + 1, origin + 3 + curlen);
|
||||||
//else
|
else
|
||||||
//scr_hide_cursor();
|
scr_hide_cursor();
|
||||||
|
|
||||||
wrefresh(win);
|
wrefresh(win);
|
||||||
ch = getch();
|
ch = getch();
|
||||||
|
@ -298,7 +298,7 @@ int scr_prompt_options(int width, char *text, char **options, int optcount) {
|
||||||
short pair;
|
short pair;
|
||||||
BOOL loop = TRUE;
|
BOOL loop = TRUE;
|
||||||
WINDOW *win;
|
WINDOW *win;
|
||||||
int text_height = calculate_height(width, strlen(text));
|
int text_height = calculate_height(width, text);
|
||||||
|
|
||||||
#ifdef WORK
|
#ifdef WORK
|
||||||
pair = SCR_PAIR(SCR_WHITE, SCR_BLACK);
|
pair = SCR_PAIR(SCR_WHITE, SCR_BLACK);
|
||||||
|
@ -320,31 +320,23 @@ int scr_prompt_options(int width, char *text, char **options, int optcount) {
|
||||||
wattroff(win, SCR_PAIR(SCR_WHITE, SCR_BLACK));
|
wattroff(win, SCR_PAIR(SCR_WHITE, SCR_BLACK));
|
||||||
|
|
||||||
for(i = 0; i < optcount; ++i)
|
for(i = 0; i < optcount; ++i)
|
||||||
maxlen = MAX(maxlen, strlen(options[i]) + 3);
|
maxlen = MIN(width, MAX(maxlen, strlen(options[i]) + 3));
|
||||||
origin = (width - maxlen) / 2;
|
origin = (width - maxlen) / 2;
|
||||||
|
|
||||||
while(loop) {
|
while(loop) {
|
||||||
origin = (width - (outlen + 3)) / 2;
|
|
||||||
wmove(win, text_height + 1, origin);
|
|
||||||
|
|
||||||
for(i = 0; i < optcount; ++i) {
|
for(i = 0; i < optcount; ++i) {
|
||||||
pair = i == selected ? SCR_PAIR(SCR_BLACK, SCR_CYAN)
|
pair = i == selected ? SCR_PAIR(SCR_BLACK, SCR_CYAN)
|
||||||
: SCR_PAIR(SCR_WHITE, SCR_BLACK);
|
: SCR_PAIR(SCR_WHITE, SCR_BLACK);
|
||||||
|
|
||||||
|
wmove(win, text_height + i + 1, origin);
|
||||||
|
wrefresh(win);
|
||||||
|
|
||||||
|
wattron(win, pair);
|
||||||
|
wprintw(win, "%s %s", i == selected ? "->" : " *", options[i]);
|
||||||
|
wattroff(win, pair);
|
||||||
}
|
}
|
||||||
|
|
||||||
wattron(win, pair);
|
wrefresh(win);
|
||||||
wprintw(win, "-> ");
|
|
||||||
|
|
||||||
wattron(win, A_UNDERLINE);
|
|
||||||
wprintw(win, out);
|
|
||||||
for(i = curlen; i < outlen; ++i)
|
|
||||||
waddch(win, ' ');
|
|
||||||
wattroff(win, A_UNDERLINE);
|
|
||||||
wattroff(win, pair);
|
|
||||||
wrefresh(win);
|
|
||||||
|
|
||||||
scr_hide_cursor();
|
scr_hide_cursor();
|
||||||
ch = getch();
|
ch = getch();
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
|
@ -363,4 +355,19 @@ int scr_prompt_options(int width, char *text, char **options, int optcount) {
|
||||||
|
|
||||||
delwin(win);
|
delwin(win);
|
||||||
return selected;
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
int scr_prompt_voptions(int width, char *text, int optcount, ...) {
|
||||||
|
int retval, i;
|
||||||
|
char **options = (char**)malloc(optcount * sizeof(char*));
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, optcount);
|
||||||
|
for(i = 0; i < optcount; ++i)
|
||||||
|
options[i] = va_arg(args, char*);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
retval = scr_prompt_options(width, text, options, optcount);
|
||||||
|
free(options);
|
||||||
|
return retval;
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -36,5 +37,6 @@ void scr_alert(int, char*);
|
||||||
BOOL scr_prompt(int, char*);
|
BOOL scr_prompt(int, char*);
|
||||||
void scr_prompt_string(int, char*, char*, int);
|
void scr_prompt_string(int, char*, char*, int);
|
||||||
int scr_prompt_options(int, char*, char**, int);
|
int scr_prompt_options(int, char*, char**, int);
|
||||||
|
int scr_prompt_voptions(int, char*, int, ...);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
20
src/main.c
20
src/main.c
|
@ -4,15 +4,21 @@
|
||||||
#include "server/server.h"
|
#include "server/server.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
packet_context_init(2);
|
packet_context_init(5);
|
||||||
|
|
||||||
packet_context_register(PCK_CTX_C2S, PCK_ID_REGISTER, 0, 2, 9, 2);
|
packet_context_register(PCK_CTX_C2S, PCK_ID_CLERIC_REQ, 0, 1, 1);
|
||||||
packet_context_register(PCK_CTX_C2S, PCK_ID_LOGIN, 0, 2, 9, 2);
|
packet_context_register(PCK_CTX_C2S, PCK_ID_ALERT, 0, 2, 1, 1);
|
||||||
packet_context_register(PCK_CTX_C2S, PCK_ID_CHANGE_CTX, 0, 2, 1, 2);
|
packet_context_register(PCK_CTX_C2S, PCK_ID_PROMPT_BOOL, 0, 3, 1, 1, 1);
|
||||||
|
packet_context_register(PCK_CTX_C2S, PCK_ID_PROMPT_STR, 0, 3, 1, 1, 256);
|
||||||
|
packet_context_register(PCK_CTX_C2S, PCK_ID_PROMPT_LIST, 0, 3, 1, 1, 2);
|
||||||
|
packet_context_register(PCK_CTX_C2S, PCK_ID_CHANGE_CTX, 0, 2, 1, 2);
|
||||||
|
|
||||||
packet_context_register(PCK_CTX_S2C, PCK_ID_REGISTER, 0, 2, 1, 17);
|
packet_context_register(PCK_CTX_S2C, PCK_ID_CLERIC_REQ, 0, 2, 1, 1);
|
||||||
packet_context_register(PCK_CTX_S2C, PCK_ID_LOGIN, 0, 3, 1, 2, 17);
|
packet_context_register(PCK_CTX_S2C, PCK_ID_ALERT, 0, 4, 1, 1, 2, 512);
|
||||||
packet_context_register(PCK_CTX_S2C, PCK_ID_CHANGE_CTX, 0, 1, 2);
|
packet_context_register(PCK_CTX_S2C, PCK_ID_PROMPT_BOOL, 0, 4, 1, 1, 2, 512);
|
||||||
|
packet_context_register(PCK_CTX_S2C, PCK_ID_PROMPT_STR, 0, 5, 1, 1, 2, 512, 1);
|
||||||
|
packet_context_register(PCK_CTX_S2C, PCK_ID_PROMPT_LIST, 0, 6, 1, 1, 2, 512, 1, 256);
|
||||||
|
packet_context_register(PCK_CTX_S2C, PCK_ID_CHANGE_CTX, 0, 1, 2);
|
||||||
|
|
||||||
if(argc == 2 && strcmp(argv[1], "server") == 0) {
|
if(argc == 2 && strcmp(argv[1], "server") == 0) {
|
||||||
register_spawn_type(SPAWN_SERVER);
|
register_spawn_type(SPAWN_SERVER);
|
||||||
|
|
10
src/packet.c
10
src/packet.c
|
@ -116,7 +116,7 @@ packet_t* packet_init_out(uint8_t id, uint16_t iterations) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
packet_ctx_t *out = &(ctx.out[id]);
|
packet_ctx_t *out = &(ctx.out[id]);
|
||||||
int regions = out->region_count;
|
uint32_t regions = out->region_count, length;
|
||||||
if(out->iter_start != 0)
|
if(out->iter_start != 0)
|
||||||
regions = out->iter_start + (iterations * out->iter_count);
|
regions = out->iter_start + (iterations * out->iter_count);
|
||||||
|
|
||||||
|
@ -128,9 +128,15 @@ packet_t* packet_init_out(uint8_t id, uint16_t iterations) {
|
||||||
packet->region_count = regions;
|
packet->region_count = regions;
|
||||||
packet->region_lengths = out->region_lengths;
|
packet->region_lengths = out->region_lengths;
|
||||||
packet->length = out->pre_iter_length + out->iter_length * iterations;
|
packet->length = out->pre_iter_length + out->iter_length * iterations;
|
||||||
packet->raw = (uint8_t*)malloc((7 * packet->length) * sizeof(uint8_t));
|
packet->raw = (uint8_t*)malloc((7 + packet->length) * sizeof(uint8_t));
|
||||||
packet_fill_regions(packet, out);
|
packet_fill_regions(packet, out);
|
||||||
|
|
||||||
|
packet->raw[0] = 0xDE;
|
||||||
|
packet->raw[1] = 0xAD;
|
||||||
|
packet->raw[2] = id;
|
||||||
|
length = htonl(packet->length);
|
||||||
|
memcpy(packet->raw + 3, &length, 4);
|
||||||
|
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/packet.h
12
src/packet.h
|
@ -14,9 +14,15 @@
|
||||||
#define PCK_IN 0
|
#define PCK_IN 0
|
||||||
#define PCK_OUT 1
|
#define PCK_OUT 1
|
||||||
|
|
||||||
#define PCK_ID_REGISTER 0
|
#define PCK_CLERIC_REG 0
|
||||||
#define PCK_ID_LOGIN 1
|
#define PCK_CLERIC_LOGIN 1
|
||||||
#define PCK_ID_CHANGE_CTX 2
|
|
||||||
|
#define PCK_ID_CLERIC_REQ 0
|
||||||
|
#define PCK_ID_ALERT 1
|
||||||
|
#define PCK_ID_PROMPT_BOOL 2
|
||||||
|
#define PCK_ID_PROMPT_STR 3
|
||||||
|
#define PCK_ID_PROMPT_LIST 4
|
||||||
|
#define PCK_ID_CHANGE_CTX 5
|
||||||
|
|
||||||
typedef struct packet_t packet_t;
|
typedef struct packet_t packet_t;
|
||||||
struct packet_t {
|
struct packet_t {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
#include "sock.h"
|
#include "sock.h"
|
||||||
|
#include "packet.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
#include "flimit.h"
|
#include "flimit.h"
|
||||||
|
|
||||||
|
|
10
src/sock.c
10
src/sock.c
|
@ -82,17 +82,17 @@ int sock_start(socket_t *sock) {
|
||||||
return sock_server_start(sock, &hints);
|
return sock_server_start(sock, &hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sock_set_timeout(socket_t *sock, int secs, int msecs) {
|
void sock_set_timeout(socket_t *sock, uint8_t dir, int secs, int msecs) {
|
||||||
sock_set_timeout_us(sock, secs, msecs * 1000);
|
sock_set_timeout_us(sock, dir, secs, msecs * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sock_set_timeout_us(socket_t *sock, int secs, int usecs) {
|
void sock_set_timeout_us(socket_t *sock, uint8_t dir, int secs, int usecs) {
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
timeout.tv_sec = secs;
|
timeout.tv_sec = secs;
|
||||||
timeout.tv_usec = usecs;
|
timeout.tv_usec = usecs;
|
||||||
|
|
||||||
setsockopt(sock->socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout));
|
setsockopt(sock->socket, SOL_SOCKET, dir == SOCK_DIR_SEND ? SO_SNDTIMEO : SO_RCVTIMEO,
|
||||||
setsockopt(sock->socket, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, sizeof(timeout));
|
(char*)&timeout, sizeof(timeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
void sock_set_blocking(socket_t *sock) {
|
void sock_set_blocking(socket_t *sock) {
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
// socket is client connection on server's side
|
// socket is client connection on server's side
|
||||||
#define SOCK_TYPE_SERVING 2
|
#define SOCK_TYPE_SERVING 2
|
||||||
|
|
||||||
|
#define SOCK_DIR_SEND 0
|
||||||
|
#define SOCK_DIR_RECV 1
|
||||||
|
|
||||||
typedef struct socket_t socket_t;
|
typedef struct socket_t socket_t;
|
||||||
struct socket_t {
|
struct socket_t {
|
||||||
int type;
|
int type;
|
||||||
|
@ -44,9 +47,9 @@ socket_t* sock_server_init(char*);
|
||||||
int sock_start(socket_t*);
|
int sock_start(socket_t*);
|
||||||
|
|
||||||
// second int is millisecs
|
// second int is millisecs
|
||||||
void sock_set_timeout(socket_t*, int, int);
|
void sock_set_timeout(socket_t*, uint8_t, int, int);
|
||||||
// second int is microsecs
|
// second int is microsecs
|
||||||
void sock_set_timeout_us(socket_t*, int, int);
|
void sock_set_timeout_us(socket_t*, uint8_t, int, int);
|
||||||
void sock_set_blocking(socket_t*);
|
void sock_set_blocking(socket_t*);
|
||||||
void sock_set_nonblocking(socket_t*);
|
void sock_set_nonblocking(socket_t*);
|
||||||
BOOL sock_is_blocking(socket_t*);
|
BOOL sock_is_blocking(socket_t*);
|
||||||
|
|
Loading…
Reference in a new issue