equal
deleted
inserted
replaced
107 { |
107 { |
108 int cs; |
108 int cs; |
109 cs = accept(ls, NULL, NULL); |
109 cs = accept(ls, NULL, NULL); |
110 assert(cs != -1); |
110 assert(cs != -1); |
111 client_cs[nconnections++].socket = cs; |
111 client_cs[nconnections++].socket = cs; |
112 fprintf(stderr, "New connection, socket %i at pos %i.\n", cs, |
|
113 nconnections-1); |
|
114 } |
112 } |
115 for(i=0; i< nconnections; ++i) |
113 for(i=0; i< nconnections; ++i) |
116 if (FD_ISSET(client_cs[i].socket, &readset)) |
114 if (FD_ISSET(client_cs[i].socket, &readset)) |
117 { |
115 { |
118 enum Break b; |
116 enum Break b; |
143 { |
141 { |
144 int i; |
142 int i; |
145 |
143 |
146 if(client_cs[index].hasjob) |
144 if(client_cs[index].hasjob) |
147 { |
145 { |
148 printf("s: removing job [%i] %i\n", index, client_cs[index].jobid); |
|
149 s_removejob(client_cs[index].jobid); |
146 s_removejob(client_cs[index].jobid); |
150 } |
147 } |
151 |
148 |
152 for(i=index; i<(nconnections-1); ++i) |
149 for(i=index; i<(nconnections-1); ++i) |
153 { |
150 { |
165 int res; |
162 int res; |
166 |
163 |
167 s = client_cs[index].socket; |
164 s = client_cs[index].socket; |
168 |
165 |
169 /* Read the message */ |
166 /* Read the message */ |
170 res = read(s, &m, sizeof(m)); |
167 res = recv(s, &m, sizeof(m),0); |
171 if (res == -1) |
168 if (res == -1) |
172 { |
169 { |
173 sleep(60); |
170 fprintf(stderr, "Error reading from client %i, socket %i\n", |
174 fprintf(stderr, "Error reading from client %i, socket %i", |
|
175 index, s); |
171 index, s); |
176 perror("client read"); |
172 perror("client read"); |
177 exit(-1); |
173 exit(-1); |
178 } |
174 } |
179 assert(res != -1); |
|
180 if (res == 0) |
175 if (res == 0) |
181 { |
176 { |
182 close(s); |
177 close(s); |
183 remove_connection(index); |
178 remove_connection(index); |
184 return NOBREAK; |
179 return NOBREAK; |
200 } |
195 } |
201 |
196 |
202 if (m.type == LIST) |
197 if (m.type == LIST) |
203 { |
198 { |
204 s_list(client_cs[index].socket); |
199 s_list(client_cs[index].socket); |
|
200 /* We must actively close, meaning End of Lines */ |
205 close(client_cs[index].socket); |
201 close(client_cs[index].socket); |
206 remove_connection(index); |
202 remove_connection(index); |
207 } |
203 } |
208 |
204 |
209 if (m.type == ENDJOB) |
205 if (m.type == ENDJOB) |
224 |
220 |
225 s = client_cs[index].socket; |
221 s = client_cs[index].socket; |
226 |
222 |
227 m.type = RUNJOB; |
223 m.type = RUNJOB; |
228 |
224 |
229 res = write(s, &m, sizeof(m)); |
225 res = send(s, &m, sizeof(m), 0); |
230 if(res == -1) |
226 if(res == -1) |
231 perror("write"); |
227 perror("send"); |
232 } |
228 } |
233 |
229 |
234 static void s_newjob_ok(int index) |
230 static void s_newjob_ok(int index) |
235 { |
231 { |
236 int s; |
232 int s; |
242 s = client_cs[index].socket; |
238 s = client_cs[index].socket; |
243 |
239 |
244 m.type = NEWJOB_OK; |
240 m.type = NEWJOB_OK; |
245 m.u.jobid = client_cs[index].jobid; |
241 m.u.jobid = client_cs[index].jobid; |
246 |
242 |
247 res = write(s, &m, sizeof(m)); |
243 res = send(s, &m, sizeof(m), 0); |
248 if(res == -1) |
244 if(res == -1) |
249 perror("write"); |
245 perror("send"); |
250 } |
246 } |