Thu, 10 Apr 2014 12:10:09 +0200
minor improvements by using macros
1
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2014 Mike Becker. All rights reserved. |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | * |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | */ |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | #include <string.h> |
34
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
32 | #include <fcntl.h> |
1
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
33 | #include "network.h" |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
34 | |
2
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
35 | #define new_socket() socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
36 | |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
37 | int net_create(Server *server, char* port) { |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
38 | server->info = NULL; |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
39 | |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
40 | struct sockaddr_in addr; |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
41 | addr.sin_family = AF_INET; |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
42 | addr.sin_addr.s_addr = INADDR_ANY; |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
43 | addr.sin_port = htons(atoi(port)); |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
44 | |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
45 | server->fd = new_socket(); |
1
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
46 | if (server->fd > -1) { |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
47 | int true = 1; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
48 | setsockopt(server->fd, SOL_SOCKET, SO_REUSEADDR, &true, sizeof(int)); |
2
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
49 | if (bind(server->fd, (struct sockaddr*)&addr, sizeof(addr))) { |
1
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
50 | server->fd = -1; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | return 1; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | } else { |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | return 0; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
54 | } |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
55 | } else { |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
56 | return 1; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
57 | } |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | } |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
59 | |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
60 | int getaddrinfo_intrnl(char *host, char *port, struct addrinfo **info) { |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
61 | struct addrinfo hints; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
62 | memset(&hints, 0, sizeof(hints)); |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
63 | hints.ai_socktype = SOCK_STREAM; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
64 | hints.ai_protocol = IPPROTO_TCP; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
65 | |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
66 | return getaddrinfo(host, port, &hints, info); |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
67 | } |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
68 | |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
69 | int net_find(Server *server, char *host, char* port) { |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
70 | memset(server, 0, sizeof(Server)); |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
71 | server->fd = -1; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
72 | |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
73 | return getaddrinfo_intrnl(host, port, &(server->info)); |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
74 | } |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
75 | |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
76 | int net_listen(Server *server) { |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
77 | listen(server->fd, 1); |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
78 | Client* client = calloc(1, sizeof(Client)); |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
79 | client->fd = -1; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
80 | server->client = client; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
81 | |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
82 | client->fd = accept(server->fd, |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
83 | &(client->address), &(client->address_len)); |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
84 | |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
85 | return client->fd == -1; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
86 | } |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
87 | |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | int net_connect(Server *server) { |
2
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
89 | |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
90 | Client* client = calloc(1, sizeof(Client)); |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
91 | client->fd = -1; |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
92 | server->fd = new_socket(); |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
93 | server->client = client; |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
94 | |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
95 | if (server->fd == -1) { |
1
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
96 | return 1; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
97 | } |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
98 | |
2
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
99 | return connect(server->fd, server->info->ai_addr, server->info->ai_addrlen); |
1
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
100 | } |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
101 | |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
102 | int net_destroy(Server *server) { |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
103 | if (server->info) { |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
104 | freeaddrinfo(server->info); |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
105 | } |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
106 | if (server->client) { |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | shutdown(server->client->fd, SHUT_RDWR); |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
108 | free(server->client); |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
109 | } |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
110 | if (server->fd > -1) { |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
111 | return shutdown(server->fd, SHUT_RDWR); |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
112 | } |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
113 | |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
114 | return EXIT_SUCCESS; |
e5fbb8f9edbe
added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
115 | } |
2
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
116 | |
22
41bbfd4d17a3
improved network performance
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
117 | void net_send_code(int socket, uint8_t code) { |
41bbfd4d17a3
improved network performance
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
118 | send(socket, &code, sizeof(uint8_t), 0); |
3
3693fd2eb0e9
changed UI to ncurses session + added network handshake
Mike Becker <universe@uap-core.de>
parents:
2
diff
changeset
|
119 | } |
3693fd2eb0e9
changed UI to ncurses session + added network handshake
Mike Becker <universe@uap-core.de>
parents:
2
diff
changeset
|
120 | |
22
41bbfd4d17a3
improved network performance
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
121 | void net_send_data(int socket, uint8_t code, void *data, size_t len) { |
41bbfd4d17a3
improved network performance
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
122 | uint8_t pkg[len+1]; |
41bbfd4d17a3
improved network performance
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
123 | pkg[0] = code; |
41bbfd4d17a3
improved network performance
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
124 | memcpy(pkg+1, data, len); |
41bbfd4d17a3
improved network performance
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
125 | send(socket, pkg, len+1, 0); |
2
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
126 | } |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
127 | |
22
41bbfd4d17a3
improved network performance
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
128 | uint8_t net_recieve_code(int socket) { |
41bbfd4d17a3
improved network performance
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
129 | uint8_t code; |
41bbfd4d17a3
improved network performance
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
130 | recv(socket, &code, sizeof(uint8_t), 0); |
41bbfd4d17a3
improved network performance
Mike Becker <universe@uap-core.de>
parents:
7
diff
changeset
|
131 | return code; |
2
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
132 | } |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
133 | |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
134 | void net_recieve_data(int socket, void *data, size_t len) { |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
135 | recv(socket, data, len, 0); |
0a08f79c320d
fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents:
1
diff
changeset
|
136 | } |
34
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
137 | |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
138 | int net_setnonblocking(int socket, _Bool nonblocking) { |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
139 | int opts = fcntl(socket, F_GETFL); |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
140 | if (opts < 0) { |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
141 | return 1; |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
142 | } |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
143 | |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
144 | if (nonblocking) { |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
145 | opts |= O_NONBLOCK; |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
146 | } else { |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
147 | opts &= ~O_NONBLOCK; |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
148 | } |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
149 | if (fcntl(socket, F_SETFL, opts) < 0) { |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
150 | return 1; |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
151 | } |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
152 | |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
153 | return 0; |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
22
diff
changeset
|
154 | } |