forked from MoSync/MoSync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
85 lines (71 loc) · 1.96 KB
/
main.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Copyright (C) 2009 Mobile Sorcery AB
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License, version 2, as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#include <conprint.h>
#include <maassert.h>
#include "MAHeaders.h"
#define BUFSIZE 1024
Handle connect();
int read(Handle conn);
void write(Handle conn, int size);
int waitConn(Handle conn);
extern "C" int MAMain() {
InitConsole();
gConsoleLogging = 1;
maCreateData(RES, BUFSIZE);
Handle conn = connect();
while(true) {
int size = read(conn);
write(conn, size);
}
return 0;
}
int read(Handle conn) {
printf("Read...\n");
maConnReadToData(conn, RES, 0, BUFSIZE);
return waitConn(conn);
}
void write(Handle conn, int size) {
printf("Write...\n");
maConnWriteFromData(conn, RES, 0, size);
waitConn(conn);
}
Handle connect() {
printf("Connect...\n");
Handle conn = maConnect("socket://lazermasken.fetftp.nu:1234");
maConnClose(conn);
waitConn(conn);
return conn;
}
int waitConn(Handle conn) {
while(1) {
EVENT event;
if(maGetEvent(&event)) {
if(event.type == EVENT_TYPE_CLOSE ||
(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_0))
{
maConnClose(conn);
maExit(0);
} else if(event.type == EVENT_TYPE_KEY_PRESSED && event.key == MAK_1) {
maConnClose(conn);
} else if(event.type == EVENT_TYPE_CONN) {
printf("Result: %i\n", event.conn.result);
if(event.conn.result <= 0) {
FREEZE;
}
return event.conn.result;
}
}
maWait(0);
}
}