aboutsummaryrefslogtreecommitdiffstats
path: root/main/afpfs-ng/05-afpfs-ng-0.8.1-boxee3.patch
blob: 4b7c916da3d38c09ade4f3d4a8a74f96846fd546 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
--- afpfs-ng-0.8.1/lib/dsi.c	2011-08-26 17:27:16.000000000 +0200
+++ afpfs-ng-0.8.1/lib/dsi.c	2011-08-26 21:33:33.000000000 +0200
@@ -64,7 +64,7 @@
 	rx.size=0;
 	dsi_setup_header(server,&header,DSI_DSIGetStatus);
 	/* We're intentionally ignoring the results */
-	ret=dsi_send(server,(char *) &header,sizeof(struct dsi_header),20,
+	ret=dsi_send(server,(char *) &header,sizeof(struct dsi_header),60,
 		0,(void *) &rx);
 
 	free(rx.data);
@@ -197,6 +197,7 @@
 	new_request->other=other;
 	new_request->wait=wait;
 	new_request->next=NULL;
+      	new_request->done_waiting=0;
 
 	pthread_mutex_lock(&server->request_queue_mutex);
 	if (server->command_requests==NULL) {
@@ -208,7 +209,8 @@
 	server->stats.requests_pending++;
 	pthread_mutex_unlock(&server->request_queue_mutex);
 
-	pthread_cond_init(&new_request->condition_cond,NULL);
+	pthread_cond_init(&new_request->waiting_cond,NULL);
+	pthread_mutex_init(&new_request->waiting_mutex,NULL);
 
 	if (server->connect_state==SERVER_STATE_DISCONNECTED) {
 		char mesg[1024];
@@ -240,16 +242,12 @@
 	server->stats.tx_bytes+=size;
 	pthread_mutex_unlock(&server->send_mutex);
 
-	int tmpwait=new_request->wait;
 	#ifdef DEBUG_DSI
 	printf("=== Waiting for response for %d %s\n",
 		new_request->requestid,
 		afp_get_command_name(new_request->subcommand));
 	#endif
-	if (tmpwait<0) {
-
-		pthread_mutex_t     mutex = PTHREAD_MUTEX_INITIALIZER;
-		pthread_mutex_lock(&mutex);
+	if (new_request->wait<0) {
 
 		/* Wait forever */
 		#ifdef DEBUG_DSI
@@ -258,14 +256,17 @@
 			afp_get_command_name(new_request->subcommand));
 		#endif
 
-		rc=pthread_cond_wait( 
-			&new_request->condition_cond, 
-				&mutex );
-		pthread_mutex_unlock(&mutex);
-
-	} else if (tmpwait>0) {
-		pthread_mutex_t     mutex = PTHREAD_MUTEX_INITIALIZER;
-		pthread_mutex_lock(&mutex);
+		pthread_mutex_lock(&new_request->waiting_mutex);
+
+		if (new_request->done_waiting==0)
+			rc=pthread_cond_wait( 
+				&new_request->waiting_cond, 
+					&new_request->waiting_mutex );
+
+		pthread_mutex_unlock(&new_request->waiting_mutex);
+
+	} else if (new_request->wait>0) {
+		/* wait for new_request->wait seconds */
 
 		#ifdef DEBUG_DSI
 		printf("=== Waiting for %d %s, for %ds\n",
@@ -283,13 +284,15 @@
 			printf("=== Changing my mind, no longer waiting for %d\n",
 				new_request->requestid);
 			#endif
-			pthread_mutex_unlock(&mutex);
 			goto skip;
 		}
-		rc=pthread_cond_timedwait( 
-			&new_request->condition_cond, 
-			&mutex,&ts);
-		pthread_mutex_unlock(&mutex);
+		pthread_mutex_lock(&new_request->waiting_mutex);
+		if (new_request->done_waiting==0) 
+			rc=pthread_cond_timedwait( 
+				&new_request->waiting_cond, 
+				&new_request->waiting_mutex,&ts);
+		pthread_mutex_unlock(&new_request->waiting_mutex);
+
 		if (rc==ETIMEDOUT) {
 /* FIXME: should handle this case properly */
 			#ifdef DEBUG_DSI
@@ -299,6 +302,7 @@
 			goto out;
 		}
 	} else {
+                /* Don't wait */
 		#ifdef DEBUG_DSI
 		printf("=== Skipping wait altogether for %d\n",new_request->requestid);
 		#endif
@@ -474,7 +478,7 @@
 	}
 	server->flags=ntohs(reply1->flags);
 
-	p=(void *)((unsigned long) server->incoming_buffer + sizeof(*reply1));
+	p=(void *)((unsigned int) server->incoming_buffer + sizeof(*reply1));
 	p+=copy_from_pascal(server->server_name,p,AFP_SERVER_NAME_LEN)+1;
 
 	/* Now work our way through the variable bits */
@@ -577,6 +581,7 @@
 	unsigned char mins=0;
 	unsigned char checkmessage=0;
 
+	memset(mesg,0,AFP_LOGINMESG_LEN);
 
 	/* The logic here's undocumented.  If we get an attention packet and
 	   there's no flag, then go check the message.  Also, go check the
@@ -757,7 +762,7 @@
 		printf("<<< read() of rest of AFP, %d bytes\n",amount_to_read);
 		#endif
 		ret = read(server->fd, (void *)
-		(((unsigned long) server->incoming_buffer)+server->data_read),
+		(((unsigned int) server->incoming_buffer)+server->data_read),
 			amount_to_read);
 		if (ret<0) return -1;
 		if (ret==0) {
@@ -862,8 +867,11 @@
 			#ifdef DEBUG_DSI
 			printf("<<< Signalling %d, returning %d or %d\n",request->requestid,request->return_code,rc);
 			#endif
+			pthread_mutex_lock(&request->waiting_mutex);
 			request->wait=0;
-			pthread_cond_signal(&request->condition_cond);
+			request->done_waiting=1;
+			pthread_cond_signal(&request->waiting_cond);
+			pthread_mutex_unlock(&request->waiting_mutex);
 		} else {
 			dsi_remove_from_request_queue(server,request);
 		}