4 * Copyright (C) 2004-2011 Simon Wunderlich <dotslash@packetmixer.de>
6 * This file is part of s3d, a 3d network display server.
7 * See http://s3d.berlios.de/ for more updates.
9 * s3d is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * s3d is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with s3d; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <stdlib.h> /* free() */
27 #include <errno.h> /* errno() */
28 #include <unistd.h> /* close(), read(),write() */
29 #include <signal.h> /* SIGPIPE,SIG_ERR,SIGIO */
31 #include <SDL.h> /* SDL_SetTimer() */
34 #include <signal.h> /* sighandler_t SIG_PIPE */
36 /* here go all the network functions */
38 /* right now, there is only a basic implementation for tcp-scokets. */
39 /* upcoming are unix-sockets and ipv6-support */
43 uint8_t ibuf
[MAXPLEN
]; /* input buffer for a packet */
44 uint8_t obuf
[MAXPLEN
]; /* output buffer */
50 void sigpipe_handler(int S3DUNUSED(unused
))
52 errs("sigpip_handler()", "there is a broken pipe somewhere");
55 void sigio_handler(int S3DUNUSED(unused
))
61 /* maybe change the errors to fatal errors ... */
62 int network_init(void)
65 /* struct sigaction act; */
74 if (signal(SIGPIPE
, sigpipe_handler
) == SIG_ERR
)
75 errn("network_init():signal()", errno
);
76 if (signal(SIGIO
, sigio_handler
) == SIG_ERR
)
77 errn("s3d_init():signal()", errno
);
84 int net_turn_off(int S3DUNUSED(interval
))
86 s3dprintf(VLOW
, "Warning: High traffic on Network, interrupting read.");
91 /* this basicly polls for new connection */
92 int network_main(void)
98 if (sigio
== 1) { /* as long as there is no locking/threadsafety, do like this ... */
100 tcp_pollport(); /* this polls for new processes */
102 SDL_SetTimer(50, (SDL_TimerCallback
) net_turn_off
);
104 while (turn
&& tcp_pollproc()) {
105 } /* if there is new data, loop please. this is for testing now, and should be combined with timing later .. */
107 SDL_SetTimer(0, NULL
);
121 int n_remove(struct t_process
*p
)
123 switch (p
->con_type
) {
131 tcp_remove(p
->sockid
);
135 p
->con_type
= CON_NULL
;
139 int n_readn(struct t_process
*p
, uint8_t * str
, int s
)
141 switch (p
->con_type
) {
144 return tcp_readn(p
->sockid
, str
, s
);
148 return shm_readn((struct buf_t
*)p
->shmsock
.data_ctos
, str
, s
);
154 int n_writen(struct t_process
*p
, uint8_t * str
, int s
)
156 switch (p
->con_type
) {
159 return tcp_writen(p
->sockid
, str
, s
);
163 return shm_writen((struct buf_t
*)p
->shmsock
.data_stoc
, str
, s
);
169 int network_quit(void)