Browse Source

Make all TCP methods optional; at least FTP data is a read-only

connection and so legitimately ignores acked() and senddata().
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
04b6a1e004
2 changed files with 11 additions and 46 deletions
  1. 9
    9
      src/net/tcp.c
  2. 2
    37
      src/net/tcp/ftp.c

+ 9
- 9
src/net/tcp.c View File

137
 	assert ( conn->tcp_op->newdata != NULL );
137
 	assert ( conn->tcp_op->newdata != NULL );
138
 	assert ( conn->tcp_op->senddata != NULL );
138
 	assert ( conn->tcp_op->senddata != NULL );
139
 
139
 
140
-	if ( uip_aborted() && op->aborted ) /* optional method */
140
+	if ( uip_aborted() && op->aborted )
141
 		op->aborted ( conn );
141
 		op->aborted ( conn );
142
-	if ( uip_timedout() && op->timedout ) /* optional method */
142
+	if ( uip_timedout() && op->timedout )
143
 		op->timedout ( conn );
143
 		op->timedout ( conn );
144
-	if ( uip_closed() && op->closed ) /* optional method */
144
+	if ( uip_closed() && op->closed )
145
 		op->closed ( conn );
145
 		op->closed ( conn );
146
-	if ( uip_connected() )
146
+	if ( uip_connected() && op->connected )
147
 		op->connected ( conn );
147
 		op->connected ( conn );
148
-	if ( uip_acked() )
148
+	if ( uip_acked() && op->acked )
149
 		op->acked ( conn, uip_conn->len );
149
 		op->acked ( conn, uip_conn->len );
150
-	if ( uip_newdata() )
150
+	if ( uip_newdata() && op->newdata )
151
 		op->newdata ( conn, ( void * ) uip_appdata, uip_len );
151
 		op->newdata ( conn, ( void * ) uip_appdata, uip_len );
152
-	if ( uip_rexmit() || uip_newdata() || uip_acked() ||
153
-	     uip_connected() || uip_poll() )
152
+	if ( ( uip_rexmit() || uip_newdata() || uip_acked() ||
153
+	       uip_connected() || uip_poll() ) && op->senddata )
154
 		op->senddata ( conn );
154
 		op->senddata ( conn );
155
 }
155
 }
156
 
156
 
194
  * This calls tcp_periodic() at regular intervals.
194
  * This calls tcp_periodic() at regular intervals.
195
  */
195
  */
196
 static void tcp_step ( struct process *process ) {
196
 static void tcp_step ( struct process *process ) {
197
-	static long timeout = 0;
197
+	static unsigned long timeout = 0;
198
 
198
 
199
 	if ( currticks() > timeout ) {
199
 	if ( currticks() > timeout ) {
200
 		timeout = currticks() + ( TICKS_PER_SEC / 10 );
200
 		timeout = currticks() + ( TICKS_PER_SEC / 10 );

+ 2
- 37
src/net/tcp/ftp.c View File

58
 	ftp_complete ( ftp, 1 );
58
 	ftp_complete ( ftp, 1 );
59
 }
59
 }
60
 
60
 
61
-static void ftp_connected ( struct tcp_connection *conn ) {
62
-	struct ftp_request *ftp = tcp_to_ftp ( conn );
63
-
64
-	/* Nothing to do */
65
-}
66
-
67
 static void ftp_acked ( struct tcp_connection *conn, size_t len ) {
61
 static void ftp_acked ( struct tcp_connection *conn, size_t len ) {
68
 	struct ftp_request *ftp = tcp_to_ftp ( conn );
62
 	struct ftp_request *ftp = tcp_to_ftp ( conn );
69
 	
63
 	
70
 	ftp->already_sent += len;
64
 	ftp->already_sent += len;
71
 }
65
 }
72
 
66
 
73
-static int ftp_open_passive ( struct ftp_request *ftp ) {
67
+int ftp_open_passive ( struct ftp_request *ftp ) {
74
 	char *ptr = ftp->passive_text;
68
 	char *ptr = ftp->passive_text;
75
 	uint8_t *byte = ( uint8_t * ) ( &ftp->tcp_data.sin );
69
 	uint8_t *byte = ( uint8_t * ) ( &ftp->tcp_data.sin );
76
 	int i;
70
 	int i;
90
 	return 0;
84
 	return 0;
91
 }
85
 }
92
 
86
 
93
-static void ftp_reply ( struct ftp_request *ftp ) {
87
+void ftp_reply ( struct ftp_request *ftp ) {
94
 	char status_major = ftp->status_text[0];
88
 	char status_major = ftp->status_text[0];
95
 	int success;
89
 	int success;
96
 
90
 
190
 	.aborted	= ftp_aborted,
184
 	.aborted	= ftp_aborted,
191
 	.timedout	= ftp_timedout,
185
 	.timedout	= ftp_timedout,
192
 	.closed		= ftp_closed,
186
 	.closed		= ftp_closed,
193
-	.connected	= ftp_connected,
194
 	.acked		= ftp_acked,
187
 	.acked		= ftp_acked,
195
 	.newdata	= ftp_newdata,
188
 	.newdata	= ftp_newdata,
196
 	.senddata	= ftp_senddata,
189
 	.senddata	= ftp_senddata,
208
 	ftp_complete ( ftp, -ETIMEDOUT );
201
 	ftp_complete ( ftp, -ETIMEDOUT );
209
 }
202
 }
210
 
203
 
211
-static void ftp_data_closed ( struct tcp_connection *conn ) {
212
-	struct ftp_request *ftp = tcp_to_ftp_data ( conn );
213
-
214
-	/* Nothing to do */
215
-}
216
-
217
-static void ftp_data_connected ( struct tcp_connection *conn ) {
218
-	struct ftp_request *ftp = tcp_to_ftp_data ( conn );
219
-
220
-	/* Nothing to do */
221
-}
222
-
223
-static void ftp_data_acked ( struct tcp_connection *conn, size_t len ) {
224
-	struct ftp_request *ftp = tcp_to_ftp_data ( conn );
225
-	
226
-	/* Nothing to do */
227
-}
228
-
229
 static void ftp_data_newdata ( struct tcp_connection *conn,
204
 static void ftp_data_newdata ( struct tcp_connection *conn,
230
 			       void *data, size_t len ) {
205
 			       void *data, size_t len ) {
231
 	struct ftp_request *ftp = tcp_to_ftp_data ( conn );
206
 	struct ftp_request *ftp = tcp_to_ftp_data ( conn );
233
 	ftp->callback ( data, len );
208
 	ftp->callback ( data, len );
234
 }
209
 }
235
 
210
 
236
-static void ftp_data_senddata ( struct tcp_connection *conn ) {
237
-	struct ftp_request *ftp = tcp_to_ftp_data ( conn );
238
-	
239
-	/* Nothing to do */
240
-}
241
-
242
 static struct tcp_operations ftp_data_tcp_operations = {
211
 static struct tcp_operations ftp_data_tcp_operations = {
243
 	.aborted	= ftp_data_aborted,
212
 	.aborted	= ftp_data_aborted,
244
 	.timedout	= ftp_data_timedout,
213
 	.timedout	= ftp_data_timedout,
245
-	.closed		= ftp_data_closed,
246
-	.connected	= ftp_data_connected,
247
-	.acked		= ftp_data_acked,
248
 	.newdata	= ftp_data_newdata,
214
 	.newdata	= ftp_data_newdata,
249
-	.senddata	= ftp_data_senddata,
250
 };
215
 };
251
 
216
 
252
 /**
217
 /**

Loading…
Cancel
Save