Lines 64-70
Link Here
|
64 |
rx.size=0; |
64 |
rx.size=0; |
65 |
dsi_setup_header(server,&header,DSI_DSIGetStatus); |
65 |
dsi_setup_header(server,&header,DSI_DSIGetStatus); |
66 |
/* We're intentionally ignoring the results */ |
66 |
/* We're intentionally ignoring the results */ |
67 |
ret=dsi_send(server,(char *) &header,sizeof(struct dsi_header),20, |
67 |
ret=dsi_send(server,(char *) &header,sizeof(struct dsi_header),60, |
68 |
0,(void *) &rx); |
68 |
0,(void *) &rx); |
69 |
|
69 |
|
70 |
free(rx.data); |
70 |
free(rx.data); |
Lines 197-202
Link Here
|
197 |
new_request->other=other; |
197 |
new_request->other=other; |
198 |
new_request->wait=wait; |
198 |
new_request->wait=wait; |
199 |
new_request->next=NULL; |
199 |
new_request->next=NULL; |
|
|
200 |
new_request->done_waiting=0; |
200 |
|
201 |
|
201 |
pthread_mutex_lock(&server->request_queue_mutex); |
202 |
pthread_mutex_lock(&server->request_queue_mutex); |
202 |
if (server->command_requests==NULL) { |
203 |
if (server->command_requests==NULL) { |
Lines 208-214
Link Here
|
208 |
server->stats.requests_pending++; |
209 |
server->stats.requests_pending++; |
209 |
pthread_mutex_unlock(&server->request_queue_mutex); |
210 |
pthread_mutex_unlock(&server->request_queue_mutex); |
210 |
|
211 |
|
211 |
pthread_cond_init(&new_request->condition_cond,NULL); |
212 |
pthread_cond_init(&new_request->waiting_cond,NULL); |
|
|
213 |
pthread_mutex_init(&new_request->waiting_mutex,NULL); |
212 |
|
214 |
|
213 |
if (server->connect_state==SERVER_STATE_DISCONNECTED) { |
215 |
if (server->connect_state==SERVER_STATE_DISCONNECTED) { |
214 |
char mesg[1024]; |
216 |
char mesg[1024]; |
Lines 240-255
Link Here
|
240 |
server->stats.tx_bytes+=size; |
242 |
server->stats.tx_bytes+=size; |
241 |
pthread_mutex_unlock(&server->send_mutex); |
243 |
pthread_mutex_unlock(&server->send_mutex); |
242 |
|
244 |
|
243 |
int tmpwait=new_request->wait; |
|
|
244 |
#ifdef DEBUG_DSI |
245 |
#ifdef DEBUG_DSI |
245 |
printf("=== Waiting for response for %d %s\n", |
246 |
printf("=== Waiting for response for %d %s\n", |
246 |
new_request->requestid, |
247 |
new_request->requestid, |
247 |
afp_get_command_name(new_request->subcommand)); |
248 |
afp_get_command_name(new_request->subcommand)); |
248 |
#endif |
249 |
#endif |
249 |
if (tmpwait<0) { |
250 |
if (new_request->wait<0) { |
250 |
|
|
|
251 |
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
252 |
pthread_mutex_lock(&mutex); |
253 |
|
251 |
|
254 |
/* Wait forever */ |
252 |
/* Wait forever */ |
255 |
#ifdef DEBUG_DSI |
253 |
#ifdef DEBUG_DSI |
Lines 258-271
Link Here
|
258 |
afp_get_command_name(new_request->subcommand)); |
256 |
afp_get_command_name(new_request->subcommand)); |
259 |
#endif |
257 |
#endif |
260 |
|
258 |
|
261 |
rc=pthread_cond_wait( |
259 |
pthread_mutex_lock(&new_request->waiting_mutex); |
262 |
&new_request->condition_cond, |
260 |
|
263 |
&mutex ); |
261 |
if (new_request->done_waiting==0) |
264 |
pthread_mutex_unlock(&mutex); |
262 |
rc=pthread_cond_wait( |
265 |
|
263 |
&new_request->waiting_cond, |
266 |
} else if (tmpwait>0) { |
264 |
&new_request->waiting_mutex ); |
267 |
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
265 |
|
268 |
pthread_mutex_lock(&mutex); |
266 |
pthread_mutex_unlock(&new_request->waiting_mutex); |
|
|
267 |
|
268 |
} else if (new_request->wait>0) { |
269 |
/* wait for new_request->wait seconds */ |
269 |
|
270 |
|
270 |
#ifdef DEBUG_DSI |
271 |
#ifdef DEBUG_DSI |
271 |
printf("=== Waiting for %d %s, for %ds\n", |
272 |
printf("=== Waiting for %d %s, for %ds\n", |
Lines 283-295
Link Here
|
283 |
printf("=== Changing my mind, no longer waiting for %d\n", |
284 |
printf("=== Changing my mind, no longer waiting for %d\n", |
284 |
new_request->requestid); |
285 |
new_request->requestid); |
285 |
#endif |
286 |
#endif |
286 |
pthread_mutex_unlock(&mutex); |
|
|
287 |
goto skip; |
287 |
goto skip; |
288 |
} |
288 |
} |
289 |
rc=pthread_cond_timedwait( |
289 |
pthread_mutex_lock(&new_request->waiting_mutex); |
290 |
&new_request->condition_cond, |
290 |
if (new_request->done_waiting==0) |
291 |
&mutex,&ts); |
291 |
rc=pthread_cond_timedwait( |
292 |
pthread_mutex_unlock(&mutex); |
292 |
&new_request->waiting_cond, |
|
|
293 |
&new_request->waiting_mutex,&ts); |
294 |
pthread_mutex_unlock(&new_request->waiting_mutex); |
295 |
|
293 |
if (rc==ETIMEDOUT) { |
296 |
if (rc==ETIMEDOUT) { |
294 |
/* FIXME: should handle this case properly */ |
297 |
/* FIXME: should handle this case properly */ |
295 |
#ifdef DEBUG_DSI |
298 |
#ifdef DEBUG_DSI |
Lines 299-304
Link Here
|
299 |
goto out; |
302 |
goto out; |
300 |
} |
303 |
} |
301 |
} else { |
304 |
} else { |
|
|
305 |
/* Don't wait */ |
302 |
#ifdef DEBUG_DSI |
306 |
#ifdef DEBUG_DSI |
303 |
printf("=== Skipping wait altogether for %d\n",new_request->requestid); |
307 |
printf("=== Skipping wait altogether for %d\n",new_request->requestid); |
304 |
#endif |
308 |
#endif |
Lines 474-480
Link Here
|
474 |
} |
478 |
} |
475 |
server->flags=ntohs(reply1->flags); |
479 |
server->flags=ntohs(reply1->flags); |
476 |
|
480 |
|
477 |
p=(void *)((unsigned long) server->incoming_buffer + sizeof(*reply1)); |
481 |
p=(void *)((unsigned int) server->incoming_buffer + sizeof(*reply1)); |
478 |
p+=copy_from_pascal(server->server_name,p,AFP_SERVER_NAME_LEN)+1; |
482 |
p+=copy_from_pascal(server->server_name,p,AFP_SERVER_NAME_LEN)+1; |
479 |
|
483 |
|
480 |
/* Now work our way through the variable bits */ |
484 |
/* Now work our way through the variable bits */ |
Lines 577-582
Link Here
|
577 |
unsigned char mins=0; |
581 |
unsigned char mins=0; |
578 |
unsigned char checkmessage=0; |
582 |
unsigned char checkmessage=0; |
579 |
|
583 |
|
|
|
584 |
memset(mesg,0,AFP_LOGINMESG_LEN); |
580 |
|
585 |
|
581 |
/* The logic here's undocumented. If we get an attention packet and |
586 |
/* The logic here's undocumented. If we get an attention packet and |
582 |
there's no flag, then go check the message. Also, go check the |
587 |
there's no flag, then go check the message. Also, go check the |
Lines 757-763
Link Here
|
757 |
printf("<<< read() of rest of AFP, %d bytes\n",amount_to_read); |
762 |
printf("<<< read() of rest of AFP, %d bytes\n",amount_to_read); |
758 |
#endif |
763 |
#endif |
759 |
ret = read(server->fd, (void *) |
764 |
ret = read(server->fd, (void *) |
760 |
(((unsigned long) server->incoming_buffer)+server->data_read), |
765 |
(((unsigned int) server->incoming_buffer)+server->data_read), |
761 |
amount_to_read); |
766 |
amount_to_read); |
762 |
if (ret<0) return -1; |
767 |
if (ret<0) return -1; |
763 |
if (ret==0) { |
768 |
if (ret==0) { |
Lines 862-869
Link Here
|
862 |
#ifdef DEBUG_DSI |
867 |
#ifdef DEBUG_DSI |
863 |
printf("<<< Signalling %d, returning %d or %d\n",request->requestid,request->return_code,rc); |
868 |
printf("<<< Signalling %d, returning %d or %d\n",request->requestid,request->return_code,rc); |
864 |
#endif |
869 |
#endif |
|
|
870 |
pthread_mutex_lock(&request->waiting_mutex); |
865 |
request->wait=0; |
871 |
request->wait=0; |
866 |
pthread_cond_signal(&request->condition_cond); |
872 |
request->done_waiting=1; |
|
|
873 |
pthread_cond_signal(&request->waiting_cond); |
874 |
pthread_mutex_unlock(&request->waiting_mutex); |
867 |
} else { |
875 |
} else { |
868 |
dsi_remove_from_request_queue(server,request); |
876 |
dsi_remove_from_request_queue(server,request); |
869 |
} |
877 |
} |