Bladeren bron

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 jaren geleden
bovenliggende
commit
b8618d76db
1 gewijzigde bestanden met toevoegingen van 11 en 42 verwijderingen
  1. 11
    42
      src/net/tcp.c

+ 11
- 42
src/net/tcp.c Bestand weergeven

@@ -210,7 +210,9 @@ static int tcp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
210 210
 	DBGC ( tcp, "TCP %p allocated\n", tcp );
211 211
 	memset ( tcp, 0, sizeof ( *tcp ) );
212 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 216
 	tcp->snd_seq = random();
215 217
 	INIT_LIST_HEAD ( &tcp->queue );
216 218
 	tcp->timer.expired = tcp_expired;
@@ -221,6 +223,9 @@ static int tcp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
221 223
 	if ( ( rc = tcp_bind ( tcp, bind_port ) ) != 0 )
222 224
 		goto err;
223 225
 
226
+	/* Start timer to initiate SYN */
227
+	start_timer ( &tcp->timer );
228
+
224 229
 	/* Attach parent interface, transfer reference to connection
225 230
 	 * list and return
226 231
 	 */
@@ -360,6 +365,10 @@ static int tcp_xmit ( struct tcp_connection *tcp, int force_send ) {
360 365
 	size_t window;
361 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 372
 	/* Calculate both the actual (payload) and sequence space
364 373
 	 * lengths that we wish to transmit.
365 374
 	 */
@@ -869,19 +878,6 @@ struct tcpip_protocol tcp_protocol __tcpip_protocol = {
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 882
  * Close interface
887 883
  *
@@ -899,27 +895,6 @@ static void tcp_xfer_close ( struct xfer_interface *xfer, int rc ) {
899 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 899
  * Seek to position
925 900
  *
@@ -933,9 +908,6 @@ static int tcp_xfer_seek ( struct xfer_interface *xfer, off_t offset,
933 908
 	struct tcp_connection *tcp =
934 909
 		container_of ( xfer, struct tcp_connection, xfer );
935 910
 
936
-	/* Ensure connection has been started */
937
-	tcp_ensure_started ( tcp );
938
-
939 911
 	/* TCP doesn't support seeking to arbitrary positions */
940 912
 	if ( ( whence != SEEK_CUR ) || ( offset != 0 ) )
941 913
 		return -EINVAL;
@@ -963,9 +935,6 @@ static int tcp_xfer_deliver_iob ( struct xfer_interface *xfer,
963 935
 	struct tcp_connection *tcp =
964 936
 		container_of ( xfer, struct tcp_connection, xfer );
965 937
 
966
-	/* Ensure connection has been started */
967
-	tcp_ensure_started ( tcp );
968
-
969 938
 	/* Enqueue packet */
970 939
 	list_add_tail ( &iobuf->list, &tcp->queue );
971 940
 
@@ -979,7 +948,7 @@ static int tcp_xfer_deliver_iob ( struct xfer_interface *xfer,
979 948
 static struct xfer_interface_operations tcp_xfer_operations = {
980 949
 	.close		= tcp_xfer_close,
981 950
 	.vredirect	= ignore_xfer_vredirect,
982
-	.request	= tcp_xfer_request,
951
+	.request	= ignore_xfer_request,
983 952
 	.seek		= tcp_xfer_seek,
984 953
 	.alloc_iob	= default_xfer_alloc_iob,
985 954
 	.deliver_iob	= tcp_xfer_deliver_iob,

Laden…
Annuleren
Opslaan