Subversion Repositories Kolibri OS

Rev

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

Rev 1534 Rev 1536
Line 13... Line 13...
13
;;         GNU GENERAL PUBLIC LICENSE                              ;;
13
;;         GNU GENERAL PUBLIC LICENSE                              ;;
14
;;          Version 2, June 1991                                   ;;
14
;;          Version 2, June 1991                                   ;;
15
;;                                                                 ;;
15
;;                                                                 ;;
16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 17... Line 17...
17
 
17
 
Line 18... Line 18...
18
$Revision: 1534 $
18
$Revision: 1536 $
Line 19... Line 19...
19
 
19
 
20
virtual at 0
20
virtual at 0
Line 33... Line 33...
33
	.errorcode		dd ?
33
	.errorcode		dd ?
Line 34... Line 34...
34
 
34
 
35
	.options		dd ?
35
	.options		dd ?
Line -... Line 36...
-
 
36
	.state			dd ?
-
 
37
 
-
 
38
	.snd_proc		dd ?
36
	.state			dd ?
39
	.rcv_proc		dd ?
37
 
40
 
Line 38... Line 41...
38
	.end:
41
	.end:
Line 259... Line 262...
259
	DEBUGF	1,"socket error\n"
262
	DEBUGF	1,"socket error\n"
260
	mov	dword [esp+32], -1
263
	mov	dword [esp+32], -1
Line 261... Line 264...
261
 
264
 
Line -... Line 265...
-
 
265
	ret
262
	ret
266
 
263
 
267
align 4
264
sock_sysfn_table:
268
sock_sysfn_table:
265
	dd	SOCKET_open	; 0
269
	dd	SOCKET_open	; 0
266
	dd	SOCKET_close	; 1
270
	dd	SOCKET_close	; 1
Line 286... Line 290...
286
;
290
;
287
;-----------------------------------------------------------------
291
;-----------------------------------------------------------------
288
align 4
292
align 4
289
SOCKET_open:
293
SOCKET_open:
Line 290... Line 294...
290
 
294
 
Line 291... Line 295...
291
	DEBUGF	1,"socket_open: domain: %u, type: %u protocol: %x\n", ecx, edx, esi
295
	DEBUGF	1,"SOCKET_open: domain: %u, type: %u protocol: %x\n", ecx, edx, esi
292
 
296
 
Line 293... Line 297...
293
	call	SOCKET_alloc
297
	call	SOCKET_alloc
294
	jz	s_error
298
	jz	s_error
295
 
299
 
Line 296... Line 300...
296
	mov	[eax + SOCKET.Domain], ecx
300
	mov	[eax + SOCKET.Domain], ecx
Line 297... Line 301...
297
	mov	[eax + SOCKET.Type], edx
301
	mov	[eax + SOCKET.Type], edx
298
	mov	[eax + SOCKET.Protocol], esi
302
	mov	[eax + SOCKET.Protocol], esi
-
 
303
 
-
 
304
	mov	[esp+32], edi			; return socketnumber
-
 
305
 
Line -... Line 306...
-
 
306
	cmp	ecx, AF_INET4
-
 
307
	jne	.no_inet4
299
 
308
 
300
	mov	[esp+32], edi
309
	push	[IP_LIST]
Line 301... Line 310...
301
 
310
	pop	[eax + IP_SOCKET.LocalIP]	; fill in local ip number
302
	cmp	ecx, AF_INET4
311
 
Line -... Line 312...
-
 
312
	call	SOCKET_find_port		; fill in a local port number, application may change it later, or use this one
-
 
313
 
-
 
314
	cmp	edx, IP_PROTO_UDP
-
 
315
	je	.udp
303
	jnz	.no_stream
316
 
Line 304... Line 317...
304
 
317
	cmp	edx, IP_PROTO_TCP
305
	push	[IP_LIST]		  ;;;;
318
	je	.tcp
Line 306... Line 319...
306
	pop	[eax + IP_SOCKET.LocalIP] ;;;;
319
 
307
 
320
  .no_inet4:
Line 308... Line 321...
308
	cmp	edx, IP_PROTO_TCP
321
	ret
-
 
322
 
Line 309... Line 323...
309
	jnz	.no_stream
323
  .tcp:
Line -... Line 324...
-
 
324
	mov	ebx, eax
310
 
325
 
311
	mov	ebx, eax
326
	lea	eax, [ebx + STREAM_SOCKET.snd]
312
 
327
	call	SOCKET_ring_create
-
 
328
 
-
 
329
	lea	eax, [ebx + STREAM_SOCKET.rcv]
-
 
330
	call	SOCKET_ring_create
Line 313... Line 331...
313
	lea	eax, [ebx + STREAM_SOCKET.snd]
331
 
Line 373... Line 391...
373
 
391
 
Line 374... Line 392...
374
	mov	ecx, [eax + SOCKET.Type]
392
	mov	ecx, [eax + SOCKET.Type]
375
 
393
 
376
	mov	bx, word [edx + 2]
394
	mov	bx, word [edx + 2]
Line 377... Line 395...
377
	test	bx, bx
395
	test	bx, bx
378
	jz	.find_free
-
 
379
 
-
 
380
	call	SOCKET_check_port
-
 
381
;        test    bx, bx
-
 
382
	jz	s_error
-
 
383
	jmp	.got_port
-
 
384
 
-
 
385
    .find_free:
396
	jz	.use_preset_port
Line 386... Line -...
386
	call	SOCKET_find_port
-
 
387
;        test    bx, bx
397
 
388
	jz	s_error
398
	call	SOCKET_check_port
Line -... Line 399...
-
 
399
	jz	s_error
-
 
400
 
389
 
401
	DEBUGF	1,"using local port: %u\n", bx
390
    .got_port:
402
	mov	word [eax + UDP_SOCKET.LocalPort], bx
391
	DEBUGF	1,"using local port: %u\n", bx
403
 
Line 392... Line 404...
392
	mov	word [eax + UDP_SOCKET.LocalPort], bx
404
  .use_preset_port:
Line 462... Line 474...
462
	DEBUGF	1,"remote port: %u\n", bx
474
	DEBUGF	1,"remote port: %u\n", bx
Line 463... Line 475...
463
 
475
 
464
	mov	ebx, dword [edx + 4]
476
	mov	ebx, dword [edx + 4]
Line 465... Line -...
465
	mov	[eax + IP_SOCKET.RemoteIP], ebx
-
 
466
 
-
 
467
	; check if local port and IP is ok
-
 
468
 
-
 
469
	cmp	[eax + TCP_SOCKET.LocalPort], 0
-
 
470
	jne	@f
-
 
471
	call	SOCKET_find_port
-
 
472
       @@:
-
 
473
	DEBUGF	1,"local port: %u\n", [eax + TCP_SOCKET.LocalPort]:2
477
	mov	[eax + IP_SOCKET.RemoteIP], ebx
474
 
478
 
475
;;;;;
479
;;;;;
476
	mov	[eax + TCP_SOCKET.timer_persist], 0
480
	mov	[eax + TCP_SOCKET.timer_persist], 0
477
	mov	[eax + TCP_SOCKET.t_state], TCB_SYN_SENT
481
	mov	[eax + TCP_SOCKET.t_state], TCB_SYN_SENT
Line 570... Line 574...
570
 
574
 
571
	movzx	ebx, [eax + TCP_SOCKET.backlog_cur]
575
	movzx	ebx, [eax + TCP_SOCKET.backlog_cur]
572
	test	ebx, ebx
576
	test	ebx, ebx
Line 573... Line 577...
573
	jz	.unlock_err
577
	jz	.unlock_err
574
 
578
 
575
	dec	[eax + TCP_SOCKET.backlog_cur]
579
	dec	[eax + TCP_SOCKET.backlog_cur]		    ;;;;
576
	mov	eax, [eax + TCP_SOCKET.end + (ebx-1)*4]
580
	mov	eax, [eax + TCP_SOCKET.end + (ebx-1)*4]      ;;;;;
Line 577... Line 581...
577
	mov	[eax + SOCKET.lock], 0
581
	mov	[eax + SOCKET.lock], 0			       ;;;;
Line 578... Line 582...
578
	mov	dword [esp+32], 0
582
	mov	dword [esp+32], 0				  ;;;;
Line 615... Line 619...
615
	je	.tcp
619
	je	.tcp
Line 616... Line 620...
616
 
620
 
Line 617... Line 621...
617
	jmp	s_error
621
	jmp	s_error
618
 
622
 
619
  .tcp:
623
  .tcp:
620
	test	[eax + TCP_SOCKET.t_state], TCB_SYN_RECEIVED  ;;;;;;
-
 
621
	jz	.free
-
 
Line -... Line 624...
-
 
624
	cmp	[eax + TCP_SOCKET.t_state], TCB_SYN_RECEIVED	; state must be LISTEN, SYN_SENT or CLOSED
622
 
625
	jl	.free
Line 623... Line 626...
623
  ;;;      call    TCP_output
626
 
Line 624... Line -...
624
 
-
 
625
  ;;;      mov     dword [esp+32], 0
-
 
626
 
627
	call	TCP_output
627
  ;;;      ret
628
	mov	dword [esp+32], 0
628
 
629
 
Line 629... Line 630...
629
;       state must be LISTEN, SYN_SENT, CLOSED or maybe even invalid
630
	ret
Line 647... Line 648...
647
;
648
;
648
;-----------------------------------------------------------------
649
;-----------------------------------------------------------------
649
align 4
650
align 4
650
SOCKET_receive:
651
SOCKET_receive:
Line 651... Line 652...
651
 
652
 
Line 652... Line 653...
652
	DEBUGF	1,"socket_receive: socknum: %u bufaddr: %x, buflength: %u, flags: %x\n", ecx, edx, esi, edi
653
	DEBUGF	1,"SOCKET_receive: socknum: %u bufaddr: %x, buflength: %u, flags: %x, ", ecx, edx, esi, edi
653
 
654
 
Line 654... Line 655...
654
	call	SOCKET_num_to_ptr
655
	call	SOCKET_num_to_ptr
655
	jz	s_error
-
 
Line 656... Line -...
656
 
-
 
657
	cmp	[eax + SOCKET.Type], IP_PROTO_TCP	;;;;;;;;
-
 
658
	je	.tcp
-
 
659
 
-
 
660
	mov	ebx, esi
-
 
661
	get_from_queue (eax + SOCKET_QUEUE_LOCATION),\
-
 
Line -... Line 656...
-
 
656
	jz	s_error
-
 
657
 
-
 
658
	jmp	[eax + SOCKET.rcv_proc]
-
 
659
 
-
 
660
 
-
 
661
 
-
 
662
align 4
662
		       SOCKET_QUEUE_SIZE,\
663
SOCKET_receive_udp:
Line -... Line 664...
-
 
664
 
-
 
665
	DEBUGF	1,"type: UDP\n"
663
		       socket_queue_entry.size,\
666
 
664
		       s_error
667
	mov	ebx, esi
Line 665... Line 668...
665
		       ; destroys esi and ecx
668
	mov	edi, edx					; addr to buffer
666
 
669
 
667
	mov	edi, edx					; addr to buffer
-
 
668
 
-
 
Line 669... Line -...
669
	mov	ecx, [esi + socket_queue_entry.data_size]
-
 
670
	DEBUGF	1,"Got %u bytes of data\n", ecx
670
	get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, socket_queue_entry.size, s_error	; destroys esi and ecx
671
 
671
 
672
	cmp	ecx, ebx
672
	mov	ecx, [esi + socket_queue_entry.data_size]
673
	jle	.large_enough
673
	DEBUGF	1,"Got %u bytes of data\n", ecx
Line 674... Line 674...
674
	DEBUGF	1,"Buffer too small...\n"
674
 
675
	jmp	s_error
675
	cmp	ecx, ebx
676
 
676
	jg	.too_small
677
  .large_enough:
677
 
-
 
678
	push	[esi + socket_queue_entry.buf_ptr]		; save the buffer addr so we can clear it later
678
	push	[esi + socket_queue_entry.buf_ptr]	       ; save the buffer addr so we can clear it later
679
	mov	esi, [esi + socket_queue_entry.data_ptr]
679
	mov	esi, [esi + socket_queue_entry.data_ptr]
680
	DEBUGF	1,"Source buffer: %x, real addr: %x\n", [esp], esi
680
	DEBUGF	1,"Source buffer: %x, real addr: %x\n", [esp], esi
681
	mov	dword[esp+32+4], ecx				; return number of bytes copied
-
 
682
 
681
	mov	dword[esp+32+4], ecx				; return number of bytes copied in ebx
683
; copy the data
682
 
684
	shr	ecx, 1
683
; copy the data
685
	jnc	.nb
684
	shr	ecx, 1
686
	movsb
685
	jnc	.nb
-
 
Line 686... Line 687...
686
	movsb
687
  .nb:
687
.nb:	shr	ecx, 1
688
	shr	ecx, 1
Line 688... Line 689...
688
	jnc	.nw
689
	jnc	.nw
-
 
690
	movsw
-
 
691
  .nw:
-
 
692
	test	ecx, ecx
-
 
693
	jz	.nd
-
 
694
	rep	movsd
-
 
695
  .nd:
-
 
696
 
-
 
697
	call	kernel_free					; remove the packet
Line 689... Line 698...
689
	movsw
698
	ret
690
.nw:	test	ecx, ecx
699
 
691
	jz	.nd
700
  .too_small:
692
	rep	movsd
701
 
693
.nd:
702
	DEBUGF	1,"Buffer too small...\n"
Line 694... Line 703...
694
; remove the packet     ;;; TODO: only if it is empty!!
703
	jmp	s_error
Line 695... Line 704...
695
 
704
 
Line 696... Line 705...
696
	call	kernel_free
705
align 4
Line 722... Line 731...
722
;
731
;
723
;-----------------------------------------------------------------
732
;-----------------------------------------------------------------
724
align 4
733
align 4
725
SOCKET_send:
734
SOCKET_send:
Line 726... Line 735...
726
 
735
 
Line 727... Line 736...
727
	DEBUGF	1,"socket_send: socknum: %u sockaddr: %x, length: %u, flags: %x\n", ecx, edx, esi, edi
736
	DEBUGF	1,"SOCKET_send: socknum: %u sockaddr: %x, length: %u, flags: %x, ", ecx, edx, esi, edi
728
 
737
 
Line 729... Line 738...
729
	call	SOCKET_num_to_ptr
738
	call	SOCKET_num_to_ptr
730
	jz	s_error
-
 
731
 
-
 
732
	cmp	word [eax + SOCKET.Domain], AF_INET4
-
 
733
	je	.af_inet4
-
 
734
 
-
 
735
	jmp	s_error
-
 
Line 736... Line -...
736
 
-
 
737
  .af_inet4:
-
 
738
	DEBUGF	1,"af_inet4\n"
-
 
739
 
-
 
740
	cmp	[eax + IP_SOCKET.LocalIP], 0
-
 
Line 741... Line -...
741
	jne	@f
-
 
742
	mov	ebx, [IP_LIST]				;;;;
-
 
Line 743... Line -...
743
	mov	dword [eax + IP_SOCKET.LocalIP], ebx
-
 
744
       @@:
739
	jz	s_error
745
 
-
 
746
	cmp	[eax + SOCKET.Type], IP_PROTO_TCP
740
 
Line 747... Line -...
747
	je	.tcp
-
 
748
 
741
	jmp	[eax + SOCKET.snd_proc]
Line 749... Line -...
749
	cmp	[eax + SOCKET.Type], IP_PROTO_UDP
-
 
750
	je	.udp
-
 
751
 
-
 
752
	jmp	s_error
-
 
753
 
-
 
754
  .udp:
-
 
755
	DEBUGF	1,"type: UDP\n"
-
 
756
 
-
 
757
; check if local port is valid
-
 
758
	cmp	[eax + UDP_SOCKET.LocalPort], 0
742
 
759
	jne	@f
743
 
Line 760... Line 744...
760
 
744
 
Line 761... Line 745...
761
	call	SOCKET_find_port
745
align 4
762
	jz	s_error
746
SOCKET_send_udp:
Line 763... Line -...
763
 
-
 
764
; Now, send the packet
-
 
765
     @@:
-
 
766
	mov	ecx, esi
-
 
767
	mov	esi, edx
-
 
768
 
-
 
Line 769... Line 747...
769
	call	UDP_output
747
 
770
 
748
	DEBUGF	1,"type: UDP\n"
Line 771... Line 749...
771
	mov	dword [esp+32], 0
749
 
Line 772... Line 750...
772
	ret
750
	mov	ecx, esi
773
 
751
	mov	esi, edx
774
  .tcp:
752
 
775
	DEBUGF	1,"type: TCP\n"
753
	call	UDP_output
776
 
754
 
777
; check if local port is valid
755
	mov	dword [esp+32], 0
-
 
756
	ret
778
	cmp	[eax + TCP_SOCKET.LocalPort], 0
757
 
Line 779... Line 758...
779
	jne	@f
758
 
780
 
759
align 4
Line 812... Line 791...
812
;
791
;
813
;-----------------------------------------------------------------
792
;-----------------------------------------------------------------
814
align 4
793
align 4
815
SOCKET_get_opt:
794
SOCKET_get_opt:
Line 816... Line 795...
816
 
795
 
Line 817... Line 796...
817
	DEBUGF	1,"socket_get_opt\n"
796
	DEBUGF	1,"SOCKET_get_opt\n"
818
 
797
 
Line 819... Line 798...
819
	call	SOCKET_num_to_ptr
798
	call	SOCKET_num_to_ptr
Line 892... Line 871...
892
;
871
;
893
;-----------------------------------------------------------------
872
;-----------------------------------------------------------------
894
align 4
873
align 4
895
SOCKET_find_port:
874
SOCKET_find_port:
Line 896... Line 875...
896
 
875
 
Line 897... Line 876...
897
	DEBUGF	1,"socket_find_free_port\n"
876
	DEBUGF	1,"SOCKET_find_port\n"
Line 898... Line 877...
898
 
877
 
899
	push	ebx esi ecx
878
	push	ebx esi ecx
Line 954... Line 933...
954
;
933
;
955
;-----------------------------------------------------------------
934
;-----------------------------------------------------------------
956
align 4
935
align 4
957
SOCKET_check_port:
936
SOCKET_check_port:
Line 958... Line 937...
958
 
937
 
Line 959... Line 938...
959
	DEBUGF	1,"socket_check_port\n"
938
	DEBUGF	1,"SOCKET_check_port\n"
960
 
939
 
Line 961... Line 940...
961
	mov	ecx, [eax + SOCKET.Type]
940
	mov	ecx, [eax + SOCKET.Type]
Line 985... Line 964...
985
 
964
 
986
;-----------------------------------------------------------------
965
;-----------------------------------------------------------------
987
;
966
;
988
; SOCKET_input
967
; SOCKET_input
989
;
968
;
990
; Updates a socket with received data
969
; Updates a (stateless) socket with received data
991
;
970
;
992
; Note: the mutex should already be set !
971
; Note: the mutex should already be set !
993
;
972
;
994
;  IN:  eax = socket ptr
973
;  IN:  eax = socket ptr
Line 1002... Line 981...
1002
;
981
;
1003
;-----------------------------------------------------------------
982
;-----------------------------------------------------------------
1004
align 4
983
align 4
1005
SOCKET_input:
984
SOCKET_input:
Line 1006... Line 985...
1006
 
985
 
Line 1007... Line 986...
1007
	DEBUGF	1,"socket_input: socket=%x, data=%x size=%u\n", eax, esi, ecx
986
	DEBUGF	1,"SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx
1008
 
987
 
1009
	mov	dword[esp+4], ecx
988
	mov	dword[esp+4], ecx
Line 1010... Line 989...
1010
	push	esi
989
	push	esi
1011
	mov	esi, esp
-
 
1012
 
-
 
1013
	add_to_queue (eax + SOCKET_QUEUE_LOCATION),\
-
 
Line 1014... Line 990...
1014
		     SOCKET_QUEUE_SIZE,\
990
	mov	esi, esp
1015
		     socket_queue_entry.size,\
991
 
1016
		     SOCKET_input.full
992
	add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, socket_queue_entry.size, SOCKET_input.full
1017
 
993
 
Line 1179... Line 1155...
1179
;
1155
;
1180
;-----------------------------------------------------------------
1156
;-----------------------------------------------------------------
1181
align 4
1157
align 4
1182
SOCKET_ring_free:
1158
SOCKET_ring_free:
Line 1183... Line 1159...
1183
 
1159
 
Line 1184... Line 1160...
1184
	DEBUGF	1,"Trying to free %u bytes of data from ring %x\n", ecx, eax
1160
	DEBUGF	1,"SOCKET_ring_free: %u bytes from ring %x\n", ecx, eax
1185
 
1161
 
1186
	sub	[eax + RING_BUFFER.size], ecx
1162
	sub	[eax + RING_BUFFER.size], ecx
Line 1211... Line 1187...
1211
;
1187
;
1212
;-----------------------------------------------------------------
1188
;-----------------------------------------------------------------
1213
align 4
1189
align 4
1214
SOCKET_notify_owner:
1190
SOCKET_notify_owner:
Line 1215... Line 1191...
1215
 
1191
 
Line 1216... Line 1192...
1216
	DEBUGF	1,"socket_notify_owner\n"
1192
	DEBUGF	1,"SOCKET_notify_owner: %x\n", eax
1217
 
1193
 
Line 1218... Line 1194...
1218
	call	SOCKET_check
1194
	call	SOCKET_check
Line 1219... Line 1195...
1219
	jz	.error
1195
	jz	.error
Line 1220... Line 1196...
1220
 
1196
 
1221
	push	ecx eax esi
1197
	push	ecx esi
Line 1241... Line 1217...
1241
       .found_pid:
1217
       .found_pid:
1242
	shl	ecx, 8
1218
	shl	ecx, 8
1243
	or	[ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
1219
	or	[ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
1244
	mov	[check_idle_semaphore], 200
1220
	mov	[check_idle_semaphore], 200
Line 1245... Line 1221...
1245
 
1221
 
Line 1246... Line 1222...
1246
	DEBUGF	1,"owner notified\n"
1222
	DEBUGF	1,"SOCKET_notify_owner: succes!\n"
1247
 
1223
 
-
 
1224
  .error2:
1248
  .error2:
1225
	pop	esi ecx
Line 1249... Line 1226...
1249
	pop	esi eax ecx
1226
 
Line 1282... Line 1259...
1282
	mov	ecx, SOCKETBUFFSIZE / 4
1259
	mov	ecx, SOCKETBUFFSIZE / 4
1283
	xor	eax, eax
1260
	xor	eax, eax
1284
	rep	stosd
1261
	rep	stosd
1285
	pop	edi eax
1262
	pop	edi eax
Line -... Line 1263...
-
 
1263
 
-
 
1264
; set send-and receive procedures to return -1
-
 
1265
	mov	[eax + SOCKET.snd_proc], s_error
-
 
1266
	mov	[eax + SOCKET.rcv_proc], s_error
1286
 
1267
 
1287
; find first free socket number and use it
-
 
1288
	mov	ebx, net_sockets
1268
; find first free socket number and use it
1289
	xor	ecx, ecx
1269
	xor	ecx, ecx
1290
  .next_socket_number:
1270
  .next_socket_number:
-
 
1271
	inc	ecx
1291
	inc	ecx
1272
	mov	ebx, net_sockets
1292
  .next_socket:
1273
  .next_socket:
1293
	mov	ebx, [ebx + SOCKET.NextPtr]
1274
	mov	ebx, [ebx + SOCKET.NextPtr]
1294
	test	ebx, ebx
1275
	test	ebx, ebx
-
 
1276
	jz	.last_socket
1295
	jz	.last_socket
1277
 
1296
	cmp	[ebx + SOCKET.Number], ecx
1278
	cmp	[ebx + SOCKET.Number], ecx
1297
	jne	.next_socket
-
 
1298
	mov	ebx, net_sockets
1279
	jne	.next_socket
Line 1299... Line 1280...
1299
	jmp	.next_socket_number
1280
	jmp	.next_socket_number
1300
 
1281
 
1301
  .last_socket:
1282
  .last_socket:
Line 1318... Line 1299...
1318
	jz	@f
1299
	jz	@f
1319
	add	ebx, SOCKET.lock	; lock the next socket
1300
	add	ebx, SOCKET.lock	; lock the next socket
1320
	call	wait_mutex
1301
	call	wait_mutex
1321
	sub	ebx, SOCKET.lock
1302
	sub	ebx, SOCKET.lock
1322
	mov	[ebx + SOCKET.PrevPtr], eax
1303
	mov	[ebx + SOCKET.PrevPtr], eax
1323
	mov	[ebx + SOCKET.lock], 0
1304
	mov	[ebx + SOCKET.lock], 0	; and unlock it again
1324
       @@:
1305
       @@:
Line 1325... Line 1306...
1325
 
1306
 
1326
	mov	[net_sockets + SOCKET.NextPtr], eax
1307
	mov	[net_sockets + SOCKET.NextPtr], eax
1327
	or	eax, eax		; used to clear zero flag
1308
	or	eax, eax		; used to clear zero flag
Line 1342... Line 1323...
1342
;
1323
;
1343
;----------------------------------------------------
1324
;----------------------------------------------------
1344
align 4
1325
align 4
1345
SOCKET_free:
1326
SOCKET_free:
Line 1346... Line 1327...
1346
 
1327
 
Line 1347... Line 1328...
1347
	DEBUGF	1, "socket_free: %x\n", eax
1328
	DEBUGF	1, "SOCKET_free: %x\n", eax
1348
 
1329
 
Line 1349... Line 1330...
1349
	call	SOCKET_check
1330
	call	SOCKET_check
Line 1354... Line 1335...
1354
	call	wait_mutex
1335
	call	wait_mutex
Line 1355... Line 1336...
1355
 
1336
 
Line 1356... Line 1337...
1356
	DEBUGF	1, "freeing socket..\n"
1337
	DEBUGF	1, "freeing socket..\n"
1357
 
1338
 
Line 1358... Line 1339...
1358
	cmp	[eax + SOCKET.Domain], AF_INET4
1339
	cmp	[eax + SOCKET.Domain], AF_INET4
1359
	jnz	.no_stream
1340
	jnz	.no_tcp
Line -... Line 1341...
-
 
1341
 
1360
 
1342
	cmp	[eax + SOCKET.Type], IP_PROTO_TCP
1361
	cmp	[eax + SOCKET.Type], IP_PROTO_TCP
1343
	jnz	.no_tcp
-
 
1344
 
1362
	jnz	.no_stream
1345
	mov	ebx, eax
Line 1363... Line 1346...
1363
 
1346
	stdcall kernel_free, [ebx + STREAM_SOCKET.rcv + RING_BUFFER.start_ptr]
1364
	stdcall kernel_free, [eax + STREAM_SOCKET.rcv + RING_BUFFER.start_ptr]
1347
	stdcall kernel_free, [ebx + STREAM_SOCKET.snd + RING_BUFFER.start_ptr]
1365
	stdcall kernel_free, [eax + STREAM_SOCKET.snd + RING_BUFFER.start_ptr]
1348
	mov	eax, ebx
Line 1435... Line 1418...
1435
;
1418
;
1436
;---------------------------------------------------
1419
;---------------------------------------------------
1437
align 4
1420
align 4
1438
SOCKET_num_to_ptr:
1421
SOCKET_num_to_ptr:
Line 1439... Line 1422...
1439
 
1422
 
Line 1440... Line 1423...
1440
	DEBUGF	1,"socket_num_to_ptr: %u ", ecx
1423
	DEBUGF	1,"SOCKET_num_to_ptr: %u ", ecx
Line 1441... Line 1424...
1441
 
1424
 
1442
	mov	eax, net_sockets
1425
	mov	eax, net_sockets
Line 1467... Line 1450...
1467
;
1450
;
1468
;---------------------------------------------------
1451
;---------------------------------------------------
1469
align 4
1452
align 4
1470
SOCKET_ptr_to_num:
1453
SOCKET_ptr_to_num:
Line 1471... Line 1454...
1471
 
1454
 
Line 1472... Line 1455...
1472
	DEBUGF	1,"socket_ptr_to_num: %x ", eax
1455
	DEBUGF	1,"SOCKET_ptr_to_num: %x ", eax
1473
 
1456
 
Line 1474... Line 1457...
1474
	call	SOCKET_check
1457
	call	SOCKET_check
Line 1494... Line 1477...
1494
;
1477
;
1495
;---------------------------------------------------
1478
;---------------------------------------------------
1496
align 4
1479
align 4
1497
SOCKET_check:
1480
SOCKET_check:
Line 1498... Line 1481...
1498
 
1481
 
Line 1499... Line 1482...
1499
	DEBUGF	1,"socket_check\n"
1482
	DEBUGF	1,"SOCKET_check: %x\n", eax
1500
 
1483
 
Line 1501... Line 1484...
1501
	push	ebx
1484
	push	ebx
Line 1528... Line 1511...
1528
;
1511
;
1529
;---------------------------------------------------
1512
;---------------------------------------------------
1530
align 4
1513
align 4
1531
SOCKET_check_owner:
1514
SOCKET_check_owner:
Line 1532... Line 1515...
1532
 
1515
 
Line 1533... Line 1516...
1533
	DEBUGF	1,"socket_check_owner\n"
1516
	DEBUGF	1,"SOCKET_check_owner: %x\n", eax
1534
 
1517
 
1535
	push	ebx
1518
	push	ebx
1536
	mov	ebx, [TASK_BASE]
1519
	mov	ebx, [TASK_BASE]
Line 1556... Line 1539...
1556
;
1539
;
1557
;------------------------------------------------------
1540
;------------------------------------------------------
1558
align 4
1541
align 4
1559
SOCKET_process_end:
1542
SOCKET_process_end:
Line 1560... Line 1543...
1560
 
1543
 
Line 1561... Line 1544...
1561
	DEBUGF	1,"socket_process_end: %x\n", eax
1544
	DEBUGF	1,"SOCKET_process_end: %x\n", eax
1562
 
1545
 
Line 1563... Line 1546...
1563
	push	ebx
1546
	push	ebx