Subversion Repositories Kolibri OS

Rev

Rev 1274 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1274 Rev 1281
Line 11... Line 11...
11
;;          GNU GENERAL PUBLIC LICENSE                             ;;
11
;;          GNU GENERAL PUBLIC LICENSE                             ;;
12
;;             Version 2, June 1991                                ;;
12
;;             Version 2, June 1991                                ;;
13
;;                                                                 ;;
13
;;                                                                 ;;
14
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 15... Line 15...
15
 
15
 
Line 16... Line 16...
16
$Revision: 1274 $
16
$Revision: 1281 $
17
 
17
 
18
struct	SOCKET_head
18
struct	SOCKET_head
19
	 .PrevPtr		dd ? ; pointer to previous socket in list
19
	 .PrevPtr		dd ? ; pointer to previous socket in list
Line 332... Line 332...
332
 
332
 
333
 
333
 
Line -... Line 334...
-
 
334
  .tcp:
-
 
335
	; TODO: set sequence number to random value
Line 334... Line 336...
334
  .tcp:
336
 
Line 335... Line 337...
335
	; TODO: set sequence number to random value
337
	lea	ebx, [eax + SOCKET_head.lock]
336
 
338
	call	wait_mutex
Line 516... Line 518...
516
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.state], TCB_LISTEN
518
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.state], TCB_LISTEN
517
	je	.destroy_tcb
519
	je	.destroy_tcb
518
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.state], TCB_SYN_SENT
520
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.state], TCB_SYN_SENT
519
	je	.destroy_tcb
521
	je	.destroy_tcb
Line 520... Line -...
520
 
-
 
521
	; Now construct the response, and queue for sending by IP
-
 
522
 
-
 
523
	mov	bl, TH_FIN
-
 
524
	xor	ecx, ecx
-
 
525
	call	TCP_send
-
 
526
 
-
 
527
	; increament SND.NXT in socket
-
 
528
	lea	esi, [eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.SND_NXT]
-
 
529
	inc_INET esi
-
 
530
 
-
 
531
	; Get the socket state
-
 
532
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.state], TCB_SYN_RECEIVED
-
 
533
	je	.fin_wait_1
-
 
534
	cmp	[eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.state], TCB_ESTABLISHED
-
 
535
	je	.fin_wait_1
-
 
536
 
-
 
537
	; assume CLOSE WAIT
-
 
538
	; Send a fin, then enter last-ack state
-
 
539
	mov	[eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.state], TCB_LAST_ACK
-
 
540
	jmp	.send
-
 
541
 
-
 
542
  .fin_wait_1:
522
 
543
	; Send a fin, then enter finwait2 state
523
	; Send a fin, then enter finwait2 state
Line -... Line 524...
-
 
524
	mov	[eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.state], TCB_FIN_WAIT_1
544
	mov	[eax + SOCKET_head.end + IPv4_SOCKET.end + TCP_SOCKET.state], TCB_FIN_WAIT_1
525
 
-
 
526
	mov	bl, TH_FIN
Line 545... Line 527...
545
 
527
	xor	ecx, ecx
Line -... Line 528...
-
 
528
;        call    TCP_send
546
  .send:
529
 
Line 547... Line 530...
547
 
530
	;;;;;
548
	;;;;;
531
 
549
 
532
 
Line 569... Line 552...
569
;
552
;
570
;-----------------------------------------------------------------
553
;-----------------------------------------------------------------
571
align 4
554
align 4
572
socket_recv:
555
socket_recv:
Line 573... Line 556...
573
 
556
 
574
	DEBUGF	1,"Socket_receive: socknum: %u bufferaddress: %x, length: %u, flags: %x\n",ecx,edx,esi,edi
557
	DEBUGF	1,"Socket_receive: socknum: %u bufaddr: %x, buflength: %u, flags: %x\n",ecx,edx,esi,edi
575
	stdcall net_socket_num_to_addr, ecx		   ; get real socket address
558
	stdcall net_socket_num_to_addr, ecx		   ; get real socket address
576
	or	eax, eax
559
	or	eax, eax
Line -... Line 560...
-
 
560
	jz	s_error
-
 
561
 
577
	jz	s_error
562
	mov	ebx, esi
Line 578... Line 563...
578
 
563
 
Line 579... Line 564...
579
	DEBUGF	1,"Socket pointer: %x\n", eax
564
	DEBUGF	1,"Socket pointer: %x\n", eax
580
 
565
 
Line 581... Line 566...
581
	get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, socket_queue_entry.size, s_error
566
	get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, socket_queue_entry.size, s_error	; destroys esi and ecx
Line 582... Line 567...
582
 
567
 
583
	mov	edi, edx
568
	mov	edi, edx					; addr to buffer
584
	mov	ecx, [esi + socket_queue_entry.data_size]
569
	mov	ecx, [esi + socket_queue_entry.data_size]
585
 
570
 
586
	DEBUGF	1,"Got %u bytes of data\n", ecx
571
	DEBUGF	1,"Got %u bytes of data\n", ecx
Line 587... Line 572...
587
 
572
 
588
	cmp	ecx, edx
573
	cmp	ecx, ebx
589
	jle	.large_enough
574
	jle	.large_enough
590
	DEBUGF	1,"Buffer too small...\n"
575
	DEBUGF	1,"Buffer too small...\n"
Line 591... Line 576...
591
	jmp	s_error
576
	jmp	s_error
Line 592... Line 577...
592
  .large_enough:
577
  .large_enough:
Line 607... Line 592...
607
.nw:	test	ecx, ecx
592
.nw:	test	ecx, ecx
608
	jz	.nd
593
	jz	.nd
609
	rep	movsd
594
	rep	movsd
610
.nd:
595
.nd:
Line 611... Line 596...
611
 
596
 
Line 612... Line 597...
612
	call	kernel_free
597
	call	kernel_free					; todo: check if ALL applications had the chance to receive data
Line 613... Line 598...
613
 
598
 
Line 694... Line 679...
694
 
679
 
Line 695... Line 680...
695
     @@:
680
     @@:
696
 
681
 
697
	mov	ecx, esi
682
	mov	ecx, esi
Line 698... Line 683...
698
	mov	esi, edx
683
	mov	esi, edx
Line 699... Line 684...
699
	xor	bl , bl
684
	mov	bl, TH_PUSH + TH_ACK
700
 
685