-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterm.c
64 lines (52 loc) · 1014 Bytes
/
term.c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
#define LOG_PFX TERM
#include "term.h"
#include "socket.h"
#define PORT 7000
static socket_t s;
static void
term_on_connect(socket_t *s)
{
const char *banner =
"\nThis is the PVP console\r\n"
"-----------------------\r\n\n";
socket_out(s, banner, strlen(banner));
}
static void
term_on_disconnect(socket_t *s)
{
const char *banner =
"\r\n\nPVP console closing...\r\n";
socket_out(s, banner, strlen(banner));
}
err_t
term_init(void)
{
err_t err;
s.port = PORT;
s.on_connect = term_on_connect;
s.on_disconnect = term_on_disconnect;
err = socket_init(&s);
ON_ERROR("socket", err, done);
LOG("Waiting for console connection on %u", PORT);
while (socket_handle_connect(&s) != ERR_NONE);
LOG("Console connected");
done:
return err;
}
void
term_bye(void)
{
socket_disconnect(&s);
}
length_t
term_in(char *buf,
length_t expected)
{
return socket_in(&s, buf, expected);
}
void
term_out(const char *buf,
length_t len)
{
socket_out(&s, buf, len);
}