Browse Source

Modify data-xfer semantics: it is no longer necessary to call one of

request(), seek() or deliver_xxx() in order to start the data flow.
Autonomous generators must be genuinely autonomous (having their own
process), or otherwise arrange to be called.  TCP does this by
starting the retry timer immediately.

Add some debugging statements.
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
b8618d76db
1 changed files with 11 additions and 42 deletions
  1. 11
    42
      src/net/tcp.c

+ 11
- 42
src/net/tcp.c View File

210
 	DBGC ( tcp, "TCP %p allocated\n", tcp );
210
 	DBGC ( tcp, "TCP %p allocated\n", tcp );
211
 	memset ( tcp, 0, sizeof ( *tcp ) );
211
 	memset ( tcp, 0, sizeof ( *tcp ) );
212
 	xfer_init ( &tcp->xfer, &tcp_xfer_operations, &tcp->refcnt );
212
 	xfer_init ( &tcp->xfer, &tcp_xfer_operations, &tcp->refcnt );
213
-	tcp->tcp_state = tcp->prev_tcp_state = TCP_CLOSED;
213
+	tcp->prev_tcp_state = TCP_CLOSED;
214
+	tcp->tcp_state = TCP_STATE_SENT ( TCP_SYN );
215
+	tcp_dump_state ( tcp );
214
 	tcp->snd_seq = random();
216
 	tcp->snd_seq = random();
215
 	INIT_LIST_HEAD ( &tcp->queue );
217
 	INIT_LIST_HEAD ( &tcp->queue );
216
 	tcp->timer.expired = tcp_expired;
218
 	tcp->timer.expired = tcp_expired;
221
 	if ( ( rc = tcp_bind ( tcp, bind_port ) ) != 0 )
223
 	if ( ( rc = tcp_bind ( tcp, bind_port ) ) != 0 )
222
 		goto err;
224
 		goto err;
223
 
225
 
226
+	/* Start timer to initiate SYN */
227
+	start_timer ( &tcp->timer );
228
+
224
 	/* Attach parent interface, transfer reference to connection
229
 	/* Attach parent interface, transfer reference to connection
225
 	 * list and return
230
 	 * list and return
226
 	 */
231
 	 */
360
 	size_t window;
365
 	size_t window;
361
 	int rc;
366
 	int rc;
362
 
367
 
368
+	/* If retransmission timer is already running, do nothing */
369
+	if ( timer_running ( &tcp->timer ) )
370
+		return 0;
371
+
363
 	/* Calculate both the actual (payload) and sequence space
372
 	/* Calculate both the actual (payload) and sequence space
364
 	 * lengths that we wish to transmit.
373
 	 * lengths that we wish to transmit.
365
 	 */
374
 	 */
869
  ***************************************************************************
878
  ***************************************************************************
870
  */
879
  */
871
 
880
 
872
-/**
873
- * Ensure TCP connection has started
874
- *
875
- * @v tcp		TCP connection
876
- */
877
-static void tcp_ensure_started ( struct tcp_connection *tcp ) {
878
-	if ( ! ( tcp->tcp_state & TCP_STATE_SENT ( TCP_SYN ) ) ) {
879
-		tcp->tcp_state = TCP_SYN_SENT;
880
-		tcp_dump_state ( tcp );
881
-		tcp_xmit ( tcp, 0 );
882
-	}
883
-}
884
-
885
 /**
881
 /**
886
  * Close interface
882
  * Close interface
887
  *
883
  *
899
 	tcp_xmit ( tcp, 0 );
895
 	tcp_xmit ( tcp, 0 );
900
 }
896
 }
901
 
897
 
902
-/**
903
- * Request data
904
- *
905
- * @v xfer		Data transfer interface
906
- * @v offset		Offset to new position
907
- * @v whence		Basis for new position
908
- * @v len		Length of requested data
909
- * @ret rc		Return status code
910
- */
911
-static int tcp_xfer_request ( struct xfer_interface *xfer,
912
-			      off_t offset __unused, int whence __unused,
913
-			      size_t len __unused ) {
914
-	struct tcp_connection *tcp =
915
-		container_of ( xfer, struct tcp_connection, xfer );
916
-
917
-	/* Ensure connection has been started */
918
-	tcp_ensure_started ( tcp );
919
-
920
-	return 0;
921
-}
922
-
923
 /**
898
 /**
924
  * Seek to position
899
  * Seek to position
925
  *
900
  *
933
 	struct tcp_connection *tcp =
908
 	struct tcp_connection *tcp =
934
 		container_of ( xfer, struct tcp_connection, xfer );
909
 		container_of ( xfer, struct tcp_connection, xfer );
935
 
910
 
936
-	/* Ensure connection has been started */
937
-	tcp_ensure_started ( tcp );
938
-
939
 	/* TCP doesn't support seeking to arbitrary positions */
911
 	/* TCP doesn't support seeking to arbitrary positions */
940
 	if ( ( whence != SEEK_CUR ) || ( offset != 0 ) )
912
 	if ( ( whence != SEEK_CUR ) || ( offset != 0 ) )
941
 		return -EINVAL;
913
 		return -EINVAL;
963
 	struct tcp_connection *tcp =
935
 	struct tcp_connection *tcp =
964
 		container_of ( xfer, struct tcp_connection, xfer );
936
 		container_of ( xfer, struct tcp_connection, xfer );
965
 
937
 
966
-	/* Ensure connection has been started */
967
-	tcp_ensure_started ( tcp );
968
-
969
 	/* Enqueue packet */
938
 	/* Enqueue packet */
970
 	list_add_tail ( &iobuf->list, &tcp->queue );
939
 	list_add_tail ( &iobuf->list, &tcp->queue );
971
 
940
 
979
 static struct xfer_interface_operations tcp_xfer_operations = {
948
 static struct xfer_interface_operations tcp_xfer_operations = {
980
 	.close		= tcp_xfer_close,
949
 	.close		= tcp_xfer_close,
981
 	.vredirect	= ignore_xfer_vredirect,
950
 	.vredirect	= ignore_xfer_vredirect,
982
-	.request	= tcp_xfer_request,
951
+	.request	= ignore_xfer_request,
983
 	.seek		= tcp_xfer_seek,
952
 	.seek		= tcp_xfer_seek,
984
 	.alloc_iob	= default_xfer_alloc_iob,
953
 	.alloc_iob	= default_xfer_alloc_iob,
985
 	.deliver_iob	= tcp_xfer_deliver_iob,
954
 	.deliver_iob	= tcp_xfer_deliver_iob,

Loading…
Cancel
Save