blob: 700d741f22fcd3fc2adf4406cd5190ea1317cbbc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#ifndef COMMON_H
#define COMMON_H
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdint.h>
#include <stddef.h>
#include <wchar.h>
#define AUTHOR_LEN 13
#define TIMESTAMP_LEN 9
// port to listen on
#define PORT 9983
// How much bytes can be sent at once over the stream
// This is also Intial size for buffer used to send and receive data,
// "initial" because the buffer is tied to an arena and can grow.
// Note: must be greater than sizeof(Message) - sizeof(Message.text)
#define STREAM_LIMIT 64
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
struct Message {
u8 author[AUTHOR_LEN];
u8 timestamp[TIMESTAMP_LEN];
// includes null terminator
u16 text_len;
wchar_t *text;
} typedef Message;
#define MESSAGELEN(m) (AUTHOR_LEN + TIMESTAMP_LEN + sizeof(m.text_len)*sizeof(wchar_t) + m.text_len)
#define MESSAGELENP(m) (AUTHOR_LEN + TIMESTAMP_LEN + sizeof(m->text_len) + m->text_len*(sizeof(wchar_t)))
void message_timestamp(u8 str[TIMESTAMP_LEN])
{
time_t now;
struct tm *ltime;
time(&now);
ltime = localtime(&now);
strftime((char *)str, TIMESTAMP_LEN, "%H:%M:%S", ltime);
}
#endif
|