diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-24 21:28:16 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2009-05-24 21:28:16 +0000 |
commit | 526b5580dabbfed7cfe5439dc3a90ec727f563c2 (patch) | |
tree | 22b1af92348785daad16714ee5e2b633017e0e48 /apps/plugins/pdbox/PDa/src/u_pdsend.c | |
parent | 4f2dfcc01b260d946044ef2b6af5fe36cb772c8d (diff) | |
download | rockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.tar.gz rockbox-526b5580dabbfed7cfe5439dc3a90ec727f563c2.zip |
Cut the files in half and it might work better (note to self: check your tree is really clean before patching)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21070 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/u_pdsend.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/u_pdsend.c | 156 |
1 files changed, 0 insertions, 156 deletions
diff --git a/apps/plugins/pdbox/PDa/src/u_pdsend.c b/apps/plugins/pdbox/PDa/src/u_pdsend.c index 9f2f9232bb..4fe714d70f 100644 --- a/apps/plugins/pdbox/PDa/src/u_pdsend.c +++ b/apps/plugins/pdbox/PDa/src/u_pdsend.c | |||
@@ -155,160 +155,4 @@ void x_closesocket(int fd) | |||
155 | closesocket(fd); | 155 | closesocket(fd); |
156 | #endif | 156 | #endif |
157 | } | 157 | } |
158 | /* Copyright (c) 2000 Miller Puckette. | ||
159 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
160 | * WARRANTIES, see the file, "LICENSE.txt," in the Pd distribution. */ | ||
161 | |||
162 | /* the "pdsend" command. This is a standalone program that forwards messages | ||
163 | from its standard input to Pd via the netsend/netreceive ("FUDI") protocol. */ | ||
164 | |||
165 | #include <sys/types.h> | ||
166 | #include <string.h> | ||
167 | #include <stdio.h> | ||
168 | #include <errno.h> | ||
169 | #include <stdlib.h> | ||
170 | #ifdef UNIX | ||
171 | #include <unistd.h> | ||
172 | #include <sys/socket.h> | ||
173 | #include <netinet/in.h> | ||
174 | #include <netdb.h> | ||
175 | #define SOCKET_ERROR -1 | ||
176 | #else | ||
177 | #include <winsock.h> | ||
178 | #endif | ||
179 | |||
180 | void sockerror(char *s); | ||
181 | void x_closesocket(int fd); | ||
182 | #define BUFSIZE 4096 | ||
183 | |||
184 | int main(int argc, char **argv) | ||
185 | { | ||
186 | int sockfd, portno, protocol; | ||
187 | struct sockaddr_in server; | ||
188 | struct hostent *hp; | ||
189 | char *hostname; | ||
190 | int nretry = 10; | ||
191 | #ifdef MSW | ||
192 | short version = MAKEWORD(2, 0); | ||
193 | WSADATA nobby; | ||
194 | #endif | ||
195 | if (argc < 2 || sscanf(argv[1], "%d", &portno) < 1 || portno <= 0) | ||
196 | goto usage; | ||
197 | if (argc >= 3) | ||
198 | hostname = argv[2]; | ||
199 | else hostname = "127.0.0.1"; | ||
200 | if (argc >= 4) | ||
201 | { | ||
202 | if (!strcmp(argv[3], "tcp")) | ||
203 | protocol = SOCK_STREAM; | ||
204 | else if (!strcmp(argv[3], "udp")) | ||
205 | protocol = SOCK_DGRAM; | ||
206 | else goto usage; | ||
207 | } | ||
208 | else protocol = SOCK_STREAM; | ||
209 | #ifdef MSW | ||
210 | if (WSAStartup(version, &nobby)) sockerror("WSAstartup"); | ||
211 | #endif | ||
212 | |||
213 | sockfd = socket(AF_INET, protocol, 0); | ||
214 | if (sockfd < 0) | ||
215 | { | ||
216 | sockerror("socket()"); | ||
217 | exit(1); | ||
218 | } | ||
219 | /* connect socket using hostname provided in command line */ | ||
220 | server.sin_family = AF_INET; | ||
221 | hp = gethostbyname(hostname); | ||
222 | if (hp == 0) | ||
223 | { | ||
224 | fprintf(stderr, "%s: unknown host\n", hostname); | ||
225 | x_closesocket(sockfd); | ||
226 | exit(1); | ||
227 | } | ||
228 | memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length); | ||
229 | |||
230 | /* assign client port number */ | ||
231 | server.sin_port = htons((unsigned short)portno); | ||
232 | |||
233 | #if 0 /* try this again for 4.0; this crashed my RH 6.2 machine!) */ | ||
234 | |||
235 | /* try to connect. */ | ||
236 | for (nretry = 0; nretry < (protocol == SOCK_STREAM ? 10 : 1); nretry++) | ||
237 | |||
238 | { | ||
239 | if (nretry > 0) | ||
240 | { | ||
241 | sleep (nretry < 5 ? 1 : 5); | ||
242 | fprintf(stderr, "retrying..."); | ||
243 | } | ||
244 | if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) >= 0) | ||
245 | goto connected; | ||
246 | sockerror("connect"); | ||
247 | } | ||
248 | x_closesocket(sockfd); | ||
249 | exit(1); | ||
250 | connected: ; | ||
251 | #else | ||
252 | /* try to connect. */ | ||
253 | if (connect(sockfd, (struct sockaddr *) &server, sizeof (server)) < 0) | ||
254 | { | ||
255 | sockerror("connect"); | ||
256 | x_closesocket(sockfd); | ||
257 | exit(1); | ||
258 | } | ||
259 | #endif | ||
260 | /* now loop reading stdin and sending it to socket */ | ||
261 | while (1) | ||
262 | { | ||
263 | char buf[BUFSIZE], *bp, nsent, nsend; | ||
264 | if (!fgets(buf, BUFSIZE, stdin)) | ||
265 | break; | ||
266 | nsend = strlen(buf); | ||
267 | for (bp = buf, nsent = 0; nsent < nsend;) | ||
268 | { | ||
269 | int res = send(sockfd, buf, nsend-nsent, 0); | ||
270 | if (res < 0) | ||
271 | { | ||
272 | sockerror("send"); | ||
273 | goto done; | ||
274 | } | ||
275 | nsent += res; | ||
276 | bp += res; | ||
277 | } | ||
278 | } | ||
279 | done: | ||
280 | if (ferror(stdin)) | ||
281 | perror("stdin"); | ||
282 | exit (0); | ||
283 | usage: | ||
284 | fprintf(stderr, "usage: pdsend <portnumber> [host] [udp|tcp]\n"); | ||
285 | fprintf(stderr, "(default is localhost and tcp)\n"); | ||
286 | exit(1); | ||
287 | } | ||
288 | 158 | ||
289 | void sockerror(char *s) | ||
290 | { | ||
291 | #ifdef MSW | ||
292 | int err = WSAGetLastError(); | ||
293 | if (err == 10054) return; | ||
294 | else if (err == 10044) | ||
295 | { | ||
296 | fprintf(stderr, | ||
297 | "Warning: you might not have TCP/IP \"networking\" turned on\n"); | ||
298 | } | ||
299 | #endif | ||
300 | #ifdef UNIX | ||
301 | int err = errno; | ||
302 | #endif | ||
303 | fprintf(stderr, "%s: %s (%d)\n", s, strerror(err), err); | ||
304 | } | ||
305 | |||
306 | void x_closesocket(int fd) | ||
307 | { | ||
308 | #ifdef UNIX | ||
309 | close(fd); | ||
310 | #endif | ||
311 | #ifdef MSW | ||
312 | closesocket(fd); | ||
313 | #endif | ||
314 | } | ||