author | viric@mandarina |
Fri, 02 Oct 2009 20:42:47 +0200 | |
changeset 280 | d207fb747144 |
parent 273 | 8d1f96d0e802 |
child 285 | 0a105f193446 |
permissions | -rw-r--r-- |
49 | 1 |
/* |
2 |
Task Spooler - a task queue system for the unix user |
|
267 | 3 |
Copyright (C) 2007-2009 LluĂs Batlle i Rossell |
49 | 4 |
|
5 |
Please find the license in the provided COPYING file. |
|
6 |
*/ |
|
44 | 7 |
#include <sys/types.h> |
8 |
#include <sys/socket.h> |
|
9 |
#include <stdio.h> |
|
146 | 10 |
#include <sys/time.h> |
44 | 11 |
#include <stdlib.h> |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
49
diff
changeset
|
12 |
#include "main.h" |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
13 |
|
235
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
14 |
void send_bytes(const int fd, const char *data, int bytes) |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
15 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
16 |
int res; |
235
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
17 |
int offset = 0; |
236 | 18 |
|
235
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
19 |
while(1) |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
20 |
{ |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
21 |
res = send(fd, data + offset, bytes, 0); |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
22 |
if(res == -1) |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
23 |
{ |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
24 |
warning("Sending %i bytes to %i.", bytes, fd); |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
25 |
break; |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
26 |
} |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
27 |
if(res == bytes) |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
28 |
break; |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
29 |
offset += res; |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
30 |
bytes -= res; |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
31 |
} |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
32 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
33 |
|
235
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
34 |
int recv_bytes(const int fd, char *data, int bytes) |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
35 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
36 |
int res; |
235
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
37 |
int offset = 0; |
236 | 38 |
|
235
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
39 |
while(1) |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
40 |
{ |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
41 |
res = recv(fd, data + offset, bytes, 0); |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
42 |
if(res == -1) |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
43 |
{ |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
44 |
warning("Receiving %i bytes from %i.", bytes, fd); |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
45 |
break; |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
46 |
} |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
47 |
if(res == bytes) |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
48 |
break; |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
49 |
offset += res; |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
50 |
bytes -= res; |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
51 |
} |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
52 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
53 |
return res; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
54 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
55 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
56 |
void send_msg(const int fd, const struct msg *m) |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
57 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
58 |
int res; |
236 | 59 |
|
60 |
if (0) |
|
111
d6bc62904b5a
Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents:
92
diff
changeset
|
61 |
msgdump(stderr, m); |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
62 |
res = send(fd, m, sizeof(*m), 0); |
235
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
63 |
if(res == -1 || res != sizeof(*m)) |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
64 |
warning_msg(m, "Sending a message to %i, sent %i bytes, should " |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
65 |
"send %i.", fd, |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
66 |
res, sizeof(*m)); |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
67 |
} |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
68 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
69 |
int recv_msg(const int fd, struct msg *m) |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
70 |
{ |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
71 |
int res; |
236 | 72 |
|
21 | 73 |
res = recv(fd, m, sizeof(*m), 0); |
92
05004c52ecff
Better error reports on internal handled errors.
viric@llimona
parents:
49
diff
changeset
|
74 |
if(res == -1) |
111
d6bc62904b5a
Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents:
92
diff
changeset
|
75 |
warning_msg(m, "Receiving a message from %i.", fd); |
236 | 76 |
if (res == sizeof(*m) && 0) |
111
d6bc62904b5a
Fixed a buffer overflow in jobs.c, when sending the lines for LISTJOBS.
viric@mandarina
parents:
92
diff
changeset
|
77 |
msgdump(stderr, m); |
271
11e4c2ac9607
Fixing a problem in msg.c, which resulted in Warnings very often in ts.error.
viric@llimona
parents:
236
diff
changeset
|
78 |
if (res != sizeof(*m) && res > 0) |
235
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
79 |
warning_msg(m, "Receiving a message from %i, received %i bytes, " |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
80 |
"should have received %i.", fd, |
97064e7d2969
Assuring the send/recv loops, which didn't pay attention to data sent in
llbatlle@taga
parents:
231
diff
changeset
|
81 |
res, sizeof(*m)); |
19
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
82 |
|
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
83 |
return res; |
5efc347cca8d
The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents:
diff
changeset
|
84 |
} |