Subversion Repositories Kolibri OS

Rev

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

Rev 1542 Rev 1543
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: 1542 $
18
$Revision: 1543 $
Line 19... Line 19...
19
 
19
 
20
virtual at 0
20
virtual at 0
Line 26... Line 26...
26
 
26
 
Line 27... Line 27...
27
	.lock			dd ? ; lock mutex
27
	.lock			dd ? ; lock mutex
28
 
28
 
29
	.PID			dd ? ; application process id
29
	.PID			dd ? ; application process id
30
	.Domain 		dd ? ; INET/UNIX/..
30
	.Domain 		dd ? ; INET/UNIX/..
31
	.Type			dd ? ; RAW/UDP/TCP/...
31
	.Type			dd ? ; RAW/STREAM/DGRAP
Line 32... Line 32...
32
	.Protocol		dd ? ; ICMP/IPv4/ARP/
32
	.Protocol		dd ? ; ICMP/IPv4/ARP/TCP/UDP
33
	.errorcode		dd ?
33
;        .errorcode              dd ?
-
 
34
 
Line 34... Line 35...
34
 
35
	.options		dd ?
35
	.options		dd ?
36
	.state			dd ?
Line 36... Line 37...
36
	.state			dd ?
37
	.backlog		dw ? ; how many incomming connections that can be queued
Line 59... Line 60...
59
	TCP_SOCKET:
60
	TCP_SOCKET:
Line 60... Line 61...
60
 
61
 
61
	.LocalPort		dw ?
62
	.LocalPort		dw ?
Line 62... Line -...
62
	.RemotePort		dw ?
-
 
63
 
-
 
64
	.backlog		dw ? ; Backlog
-
 
65
	.backlog_cur		dw ? ; current size of queue for un-accept-ed connections
63
	.RemotePort		dw ?
66
 
64
 
Line 67... Line 65...
67
	.OrigRemoteIP		dd ? ; original remote IP address (used to reset to LISTEN state)
65
	.OrigRemoteIP		dd ? ; original remote IP address (used to reset to LISTEN state)
68
	.OrigRemotePort 	dw ? ; original remote port (used to reset to LISTEN state)
66
	.OrigRemotePort 	dw ? ; original remote port (used to reset to LISTEN state)
Line 188... Line 186...
188
	.snd	rd     RING_BUFFER.end/4
186
	.snd	rd     RING_BUFFER.end/4
189
	.end:
187
	.end:
Line 190... Line 188...
190
 
188
 
Line 191... Line -...
191
end virtual
-
 
192
 
189
end virtual
193
 
190
 
194
struct	socket_queue_entry
191
struct	socket_queue_entry
195
	.data_ptr	dd ?
192
	.data_ptr	dd ?
196
	.buf_ptr	dd ?
193
	.buf_ptr	dd ?
Line 201... Line 198...
201
 
198
 
Line 202... Line 199...
202
SOCKETBUFFSIZE		equ 4096     ; in bytes
199
SOCKETBUFFSIZE		equ 4096     ; in bytes
203
 
200
 
204
SOCKET_QUEUE_SIZE	equ 10	     ; maximum number ofincoming packets queued for 1 socket
201
SOCKET_QUEUE_SIZE	equ 10	     ; maximum number ofincoming packets queued for 1 socket
Line 205... Line 202...
205
; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start
202
; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start
206
SOCKET_QUEUE_LOCATION	equ SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*socket_queue_entry.size - queue.data
203
SOCKET_QUEUE_LOCATION	equ (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*socket_queue_entry.size - queue.data)
-
 
204
 
207
 
205
uglobal
208
uglobal
206
	net_sockets	rd 4
209
	net_sockets	rd 4
207
	last_socket_num dd ?
Line 219... Line 217...
219
;-----------------------------------------------------------------
217
;-----------------------------------------------------------------
220
macro	SOCKET_init {
218
macro	SOCKET_init {
Line 221... Line 219...
221
 
219
 
222
	xor	eax, eax
220
	xor	eax, eax
223
	mov	edi, net_sockets
221
	mov	edi, net_sockets
224
	mov	ecx, 4
222
	mov	ecx, 5
Line 225... Line 223...
225
	rep	stosd
223
	rep	stosd
226
 
224
 
227
       @@:
225
       @@:
Line 301... Line 299...
301
	mov	[eax + SOCKET.Protocol], esi
299
	mov	[eax + SOCKET.Protocol], esi
Line 302... Line 300...
302
 
300
 
303
	cmp	ecx, AF_INET4
301
	cmp	ecx, AF_INET4
Line 304... Line -...
304
	jne	.no_inet4
-
 
305
 
-
 
306
	push	[IP_LIST]
-
 
307
	pop	[eax + IP_SOCKET.LocalIP]	; fill in local ip number
302
	jne	.no_inet4
308
 
303
 
Line 309... Line 304...
309
	cmp	edx, SOCK_DGRAM
304
	cmp	edx, SOCK_DGRAM
310
	je	.udp
305
	je	.udp
Line 318... Line 313...
318
  .no_inet4:
313
  .no_inet4:
319
	ret
314
	ret
Line 320... Line 315...
320
 
315
 
321
align 4
316
align 4
322
  .raw:
317
  .raw:
323
;        test    esi, esi       ; IP_PROTO_IP
318
	test	esi, esi       ; IP_PROTO_IP
Line 324... Line 319...
324
;        jz      .ip
319
	jz	.ip
325
 
320
 
Line 326... Line 321...
326
	cmp	esi, IP_PROTO_ICMP
321
	cmp	esi, IP_PROTO_ICMP
Line 335... Line 330...
335
	ret
330
	ret
Line 336... Line 331...
336
 
331
 
337
align 4
332
align 4
338
  .udp:
333
  .udp:
339
	mov	[eax + SOCKET.Protocol], IP_PROTO_UDP
-
 
340
 
-
 
341
	call	SOCKET_find_port		; fill in a local port number, application may change it later, or use this one
-
 
342
 
-
 
343
	push	eax
-
 
344
	init_queue (eax + SOCKET_QUEUE_LOCATION)
-
 
345
	pop	eax
-
 
346
 
334
	mov	[eax + SOCKET.Protocol], IP_PROTO_UDP
347
	mov	[eax + SOCKET.snd_proc], SOCKET_send_udp
335
	mov	[eax + SOCKET.snd_proc], SOCKET_send_udp
348
	mov	[eax + SOCKET.rcv_proc], SOCKET_receive_dgram
-
 
349
 
336
	mov	[eax + SOCKET.rcv_proc], SOCKET_receive_dgram
Line 350... Line 337...
350
	ret
337
	ret
351
 
338
 
352
align 4
339
align 4
353
  .tcp:
-
 
354
	mov	[eax + SOCKET.Protocol], IP_PROTO_TCP
-
 
355
 
-
 
356
	call	SOCKET_find_port		; fill in a local port number, application may change it later, or use this one
-
 
357
 
-
 
358
	mov	ebx, eax
-
 
359
 
-
 
360
	lea	eax, [ebx + STREAM_SOCKET.snd]
-
 
361
	call	SOCKET_ring_create
-
 
362
 
-
 
363
	lea	eax, [ebx + STREAM_SOCKET.rcv]
-
 
364
	call	SOCKET_ring_create
340
  .tcp:
365
 
341
	mov	[eax + SOCKET.Protocol], IP_PROTO_TCP
366
	mov	[ebx + SOCKET.snd_proc], SOCKET_send_tcp
-
 
367
	mov	[ebx + SOCKET.rcv_proc], SOCKET_receive_tcp
342
	mov	[eax + SOCKET.snd_proc], SOCKET_send_tcp
Line 368... Line 343...
368
 
343
	mov	[eax + SOCKET.rcv_proc], SOCKET_receive_tcp
369
	ret
344
	ret
370
 
-
 
371
 
-
 
372
;align 4
-
 
373
;  .ip:
-
 
374
;
-
 
375
;        push    eax
345
 
376
;        init_queue (eax + SOCKET_QUEUE_LOCATION)
346
 
377
;        pop     eax
347
align 4
378
;
-
 
Line 379... Line 348...
379
;        mov     [eax + SOCKET.snd_proc], SOCKET_send_ip
348
  .ip:
380
;        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
349
	mov	[eax + SOCKET.snd_proc], SOCKET_send_ip
381
;
-
 
382
;        ret
-
 
383
 
-
 
384
 
-
 
385
align 4
-
 
386
  .icmp:
350
	mov	[eax + SOCKET.rcv_proc], SOCKET_receive_dgram
387
 
351
	ret
388
	push	eax
-
 
389
	init_queue (eax + SOCKET_QUEUE_LOCATION)
352
 
Line 390... Line 353...
390
	pop	eax
353
 
Line 424... Line 387...
424
	je	.af_unix
387
	je	.af_unix
Line 425... Line 388...
425
 
388
 
Line 426... Line 389...
426
	jmp	s_error
389
	jmp	s_error
427
 
-
 
428
  .af_unix:
390
 
Line 429... Line 391...
429
 
391
  .af_unix:
430
	; TODO: write code here
392
	; TODO: write code here
Line 437... Line 399...
437
	DEBUGF	1,"af_inet4\n"
399
	DEBUGF	1,"af_inet4\n"
Line 438... Line 400...
438
 
400
 
439
	cmp	esi, 6
401
	cmp	esi, 6
Line 440... Line 402...
440
	jl	s_error
402
	jl	s_error
441
 
-
 
442
	mov	bx, word [edx + 2]
-
 
443
	test	bx, bx
-
 
444
	jz	.use_preset_port
-
 
445
 
-
 
446
	call	SOCKET_check_port
-
 
447
	jz	s_error
-
 
448
 
403
 
Line 449... Line 404...
449
	DEBUGF	1,"using local port: %u\n", bx
404
	push	word [edx + 2]
-
 
405
	pop	word [eax + UDP_SOCKET.LocalPort]
Line 450... Line 406...
450
	mov	word [eax + UDP_SOCKET.LocalPort], bx
406
 
451
 
407
	push	dword [edx + 4]
452
  .use_preset_port:
408
	pop	[eax + IP_SOCKET.LocalIP]
Line 486... Line 442...
486
	je	.af_inet4
442
	je	.af_inet4
Line 487... Line 443...
487
 
443
 
Line 488... Line 444...
488
	jmp	s_error
444
	jmp	s_error
-
 
445
 
-
 
446
  .af_inet4:
-
 
447
	cmp	[eax + IP_SOCKET.LocalIP], 0
-
 
448
	jne	@f
-
 
449
	push	[IP_LIST]
Line 489... Line 450...
489
 
450
	pop	[eax + IP_SOCKET.LocalIP]
490
  .af_inet4:
451
       @@:
Line 491... Line 452...
491
 
452
 
Line 503... Line 464...
503
 
464
 
Line 504... Line 465...
504
	jmp	s_error
465
	jmp	s_error
505
 
466
 
-
 
467
align 4
-
 
468
  .udp:
-
 
469
	lea	ebx, [eax + SOCKET.lock]
506
align 4
470
	call	wait_mutex
507
  .udp:
471
 
-
 
472
	push	word [edx + 2]
-
 
473
	pop	[eax + UDP_SOCKET.RemotePort]
-
 
474
 
-
 
475
	push	dword [edx + 4]
-
 
476
	pop	[eax + IP_SOCKET.RemoteIP]
-
 
477
 
-
 
478
	cmp	[eax + UDP_SOCKET.LocalPort], 0
-
 
479
	jne	@f
-
 
480
	call	SOCKET_find_port
508
	mov	bx , word [edx + 2]
481
       @@:
509
	mov	word [eax + UDP_SOCKET.RemotePort], bx
-
 
Line 510... Line 482...
510
	mov	[eax + UDP_SOCKET.firstpacket], 0
482
 
511
	DEBUGF	1,"remote port: %u\n",bx
483
	mov	[eax + UDP_SOCKET.firstpacket], 0
512
 
484
 
Line -... Line 485...
-
 
485
	push	eax
513
	mov	ebx, dword [edx + 4]
486
	init_queue (eax + SOCKET_QUEUE_LOCATION)	; Set up data receiving queue
514
	mov	dword [eax + IP_SOCKET.RemoteIP], ebx
487
	pop	   eax
Line 515... Line 488...
515
	DEBUGF	1,"remote ip: %u.%u.%u.%u\n",[edx+4]:1,[edx+5]:1,[edx+6]:1,[edx+7]:1
488
 
516
 
489
	mov	[eax + SOCKET.lock], 0
517
	mov	dword [esp+32], 0
490
	mov	dword [esp+32], 0
518
	ret
491
	ret
Line 519... Line 492...
519
 
492
 
-
 
493
align 4
Line 520... Line 494...
520
align 4
494
  .tcp:
521
  .tcp:
495
	lea	ebx, [eax + SOCKET.lock]
522
	lea	ebx, [eax + SOCKET.lock]
-
 
Line 523... Line 496...
523
	call	wait_mutex
496
	call	wait_mutex
-
 
497
 
524
 
498
	push	word [edx + 2]
-
 
499
	pop	[eax + TCP_SOCKET.RemotePort]
Line 525... Line -...
525
	; fill in remote port and IP
-
 
526
 
500
 
527
	mov	bx , word [edx + 2]
501
	push	dword [edx + 4]
528
	mov	[eax + TCP_SOCKET.RemotePort], bx
502
	pop	[eax + IP_SOCKET.RemoteIP]
529
	DEBUGF	1,"remote port: %u\n", bx
503
 
530
 
504
	cmp	[eax + TCP_SOCKET.LocalPort], 0
531
	mov	ebx, dword [edx + 4]
505
	jne	@f
Line 532... Line 506...
532
	mov	[eax + IP_SOCKET.RemoteIP], ebx
506
	call	SOCKET_find_port
Line 533... Line 507...
533
 
507
       @@:
Line 534... Line 508...
534
;;;;;
508
 
535
	mov	[eax + TCP_SOCKET.timer_persist], 0
509
	mov	[eax + TCP_SOCKET.timer_persist], 0
536
	mov	[eax + TCP_SOCKET.t_state], TCB_SYN_SENT
510
	mov	[eax + TCP_SOCKET.t_state], TCB_SYN_SENT
Line -... Line 511...
-
 
511
	mov	ebx, [TCP_sequence_num]
-
 
512
	add	[TCP_sequence_num], 6400
-
 
513
	mov	[eax + TCP_SOCKET.ISS], ebx
-
 
514
	mov	[eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init
-
 
515
 
537
	mov	ebx, [TCP_sequence_num]
516
	TCP_sendseqinit eax
-
 
517
 
Line -... Line 518...
-
 
518
;        mov     [ebx + TCP_SOCKET.timer_retransmission],   ;; todo: create macro to set retransmission timer
538
	add	[TCP_sequence_num], 6400
519
 
539
	mov	[eax + TCP_SOCKET.ISS], ebx
520
	push	eax
Line 540... Line 521...
540
	mov	[eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init
521
	call	TCP_output
541
 
522
	pop	eax
-
 
523
 
-
 
524
	mov	ebx, eax
-
 
525
 
542
	TCP_sendseqinit eax
526
	lea	eax, [ebx + STREAM_SOCKET.snd]
543
 
527
	call	SOCKET_ring_create
Line -... Line 528...
-
 
528
 
-
 
529
	lea	eax, [ebx + STREAM_SOCKET.rcv]
-
 
530
	call	SOCKET_ring_create
-
 
531
 
-
 
532
	mov	[ebx + SOCKET.lock], 0
544
;;;;            mov     [ebx + TCP_SOCKET.timer_retransmission],   ;; todo: create macro to set retransmission timer
533
	mov	dword [esp+32], 0
545
 
534
	ret
Line 546... Line 535...
546
	push	eax
535
 
547
	call	TCP_output
536
align 4
Line 582... Line 571...
582
	jne	s_error
571
	jne	s_error
Line 583... Line 572...
583
 
572
 
584
	cmp	[eax + SOCKET.Protocol], IP_PROTO_TCP
573
	cmp	[eax + SOCKET.Protocol], IP_PROTO_TCP
Line 585... Line 574...
585
	jne	s_error
574
	jne	s_error
-
 
575
 
-
 
576
	cmp	[eax + TCP_SOCKET.LocalPort], 0
-
 
577
	je	s_error
-
 
578
 
-
 
579
	cmp	[eax + IP_SOCKET.LocalIP], 0
-
 
580
	jne	@f
-
 
581
	push	[IP_LIST]
Line 586... Line 582...
586
 
582
	pop	[eax + IP_SOCKET.LocalIP]
587
	; TODO: check local port number
583
       @@:
588
 
584
 
589
	cmp	edx, MAX_backlog
585
	cmp	edx, MAX_backlog
Line 590... Line 586...
590
	jle	.ok
586
	jle	@f
-
 
587
	mov	edx, MAX_backlog
591
	mov	edx, MAX_backlog
588
       @@:
-
 
589
 
-
 
590
	mov	[eax + SOCKET.backlog], dx
592
  .ok:
591
	or	[eax + SOCKET.options], SO_ACCEPTCON
-
 
592
	mov	[eax + TCP_SOCKET.t_state], TCB_LISTEN
Line 593... Line 593...
593
 
593
 
Line 594... Line 594...
594
	mov	[eax + TCP_SOCKET.backlog], dx
594
	push	eax
Line 616... Line 616...
616
	DEBUGF	1,"SOCKET_accept: socknum: %u sockaddr: %x, length: %u\n", ecx, edx, esi
616
	DEBUGF	1,"SOCKET_accept: socknum: %u sockaddr: %x, length: %u\n", ecx, edx, esi
Line 617... Line 617...
617
 
617
 
618
	call	SOCKET_num_to_ptr
618
	call	SOCKET_num_to_ptr
Line 619... Line 619...
619
	jz	s_error
619
	jz	s_error
620
 
-
 
621
	cmp	word [eax + SOCKET.Domain], AF_INET4
-
 
622
	je	.af_inet4
620
 
Line -... Line 621...
-
 
621
	test	[eax + SOCKET.options], SO_ACCEPTCON
623
 
622
	jz	s_error
Line 624... Line 623...
624
	jmp	s_error
623
 
625
 
-
 
626
  .af_inet4:
-
 
627
 
624
	cmp	word [eax + SOCKET.Domain], AF_INET4
628
	cmp	[eax + SOCKET.Protocol], IP_PROTO_TCP
-
 
629
	je	.tcp
-
 
630
 
-
 
631
	jmp	s_error
-
 
632
 
-
 
633
  .tcp:
-
 
634
 
-
 
635
	lea	ebx, [eax + SOCKET.lock]
-
 
636
	call	wait_mutex
-
 
637
 
-
 
638
	movzx	ebx, [eax + TCP_SOCKET.backlog_cur]
-
 
639
	test	ebx, ebx
-
 
640
	jz	.unlock_err
-
 
641
 
-
 
Line 642... Line 625...
642
	dec	[eax + TCP_SOCKET.backlog_cur]		    ;;;;
625
	jne	s_error
Line -... Line 626...
-
 
626
 
-
 
627
	cmp	[eax + SOCKET.Protocol], IP_PROTO_TCP
-
 
628
	jne	s_error
-
 
629
 
643
	mov	eax, [eax + TCP_SOCKET.end + (ebx-1)*4]      ;;;;;
630
	get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, s_error
Line 644... Line -...
644
	mov	[eax + SOCKET.lock], 0			       ;;;;
-
 
645
	mov	dword [esp+32], 0				  ;;;;
-
 
646
 
-
 
647
	call	TCP_output	;;;;;
-
 
Line 648... Line 631...
648
 
631
 
649
	ret
632
	mov	eax, [esi]
650
 
633
	call	SOCKET_ptr_to_num
651
  .unlock_err:
634
	jz	s_error
Line 836... Line 819...
836
 
819
 
837
	mov	[esp+32], eax
820
	mov	[esp+32], eax
Line 838... Line 821...
838
	ret
821
	ret
839
 
822
 
840
 
823
 
841
;align 4
824
align 4
842
;SOCKET_send_ip:
825
SOCKET_send_ip:
843
;
826
 
844
;        DEBUGF  1,"type: IP\n"
827
	DEBUGF	1,"type: IP\n"
845
;
828
 
846
;        mov     ecx, esi
829
	mov	ecx, esi
847
;        mov     esi, edx
830
	mov	esi, edx
848
;
831
 
849
;        call    IPv4_output_raw
832
	call	IPv4_output_raw
Line 850... Line 833...
850
;
833
 
851
;        mov     dword [esp+32], eax
834
	mov	dword [esp+32], eax
Line 852... Line 835...
852
;        ret
835
	ret
Line 1107... Line 1090...
1107
; eax = ptr to ring struct (just a buffer of the right size)
1090
; eax = ptr to ring struct (just a buffer of the right size)
1108
;
1091
;
1109
align 4
1092
align 4
1110
SOCKET_ring_create:
1093
SOCKET_ring_create:
Line -... Line 1094...
-
 
1094
 
1111
 
1095
	push	esi
-
 
1096
	mov	esi, eax
-
 
1097
 
1112
	mov	esi, eax
1098
	push	edx
-
 
1099
	stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SW
Line 1113... Line 1100...
1113
	stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SW
1100
	pop	edx
1114
 
1101
 
1115
	DEBUGF	1,"SOCKET_ring_created: %x\n", eax
1102
	DEBUGF	1,"SOCKET_ring_created: %x\n", eax
1116
	mov	[esi + RING_BUFFER.start_ptr], eax
1103
	mov	[esi + RING_BUFFER.start_ptr], eax
1117
	mov	[esi + RING_BUFFER.write_ptr], eax
1104
	mov	[esi + RING_BUFFER.write_ptr], eax
1118
	mov	[esi + RING_BUFFER.read_ptr], eax
1105
	mov	[esi + RING_BUFFER.read_ptr], eax
1119
	mov	[esi + RING_BUFFER.size], 0
1106
	mov	[esi + RING_BUFFER.size], 0
-
 
1107
	add	eax,  SOCKET_MAXDATA
-
 
1108
	mov	[esi + RING_BUFFER.end_ptr], eax
Line 1120... Line 1109...
1120
	add	eax,  SOCKET_MAXDATA
1109
	mov	eax, esi
Line 1121... Line 1110...
1121
	mov	[esi + RING_BUFFER.end_ptr], eax
1110
	pop	esi
1122
 
1111
 
Line 1289... Line 1278...
1289
	DEBUGF	1,"SOCKET_notify_owner: %x\n", eax
1278
	DEBUGF	1,"SOCKET_notify_owner: %x\n", eax
Line 1290... Line 1279...
1290
 
1279
 
1291
	call	SOCKET_check
1280
	call	SOCKET_check
Line 1292... Line 1281...
1292
	jz	.error
1281
	jz	.error
Line 1293... Line 1282...
1293
 
1282
 
Line 1294... Line 1283...
1294
	push	ecx esi
1283
	push	eax ecx esi
1295
 
1284
 
Line 1317... Line 1306...
1317
	mov	[check_idle_semaphore], 200
1306
	mov	[check_idle_semaphore], 200
Line 1318... Line 1307...
1318
 
1307
 
Line 1319... Line 1308...
1319
	DEBUGF	1,"SOCKET_notify_owner: succes!\n"
1308
	DEBUGF	1,"SOCKET_notify_owner: succes!\n"
1320
 
1309
 
Line 1321... Line 1310...
1321
  .error2:
1310
  .error2:
Line 1322... Line 1311...
1322
	pop	esi ecx
1311
	pop	esi ecx eax
Line 1361... Line 1350...
1361
; set send-and receive procedures to return -1
1350
; set send-and receive procedures to return -1
1362
	mov	[eax + SOCKET.snd_proc], s_error
1351
	mov	[eax + SOCKET.snd_proc], s_error
1363
	mov	[eax + SOCKET.rcv_proc], s_error
1352
	mov	[eax + SOCKET.rcv_proc], s_error
Line 1364... Line 1353...
1364
 
1353
 
1365
; find first free socket number and use it
1354
; find first free socket number and use it
1366
	xor	ecx, ecx
1355
	mov	ecx, [last_socket_num]
1367
  .next_socket_number:
1356
  .next_socket_number:
-
 
1357
	inc	ecx
-
 
1358
	jz	.next_socket_number	; avoid socket nr 0
-
 
1359
	cmp	ecx, -1
1368
	inc	ecx
1360
	je	.next_socket_number	; avoid socket nr -1
1369
	mov	ebx, net_sockets
1361
	mov	ebx, net_sockets
1370
  .next_socket:
1362
  .next_socket:
1371
	mov	ebx, [ebx + SOCKET.NextPtr]
1363
	mov	ebx, [ebx + SOCKET.NextPtr]
1372
	test	ebx, ebx
1364
	test	ebx, ebx
Line 1375... Line 1367...
1375
	cmp	[ebx + SOCKET.Number], ecx
1367
	cmp	[ebx + SOCKET.Number], ecx
1376
	jne	.next_socket
1368
	jne	.next_socket
1377
	jmp	.next_socket_number
1369
	jmp	.next_socket_number
Line 1378... Line 1370...
1378
 
1370
 
-
 
1371
  .last_socket:
1379
  .last_socket:
1372
	mov	[last_socket_num], ecx
1380
	mov	[eax + SOCKET.Number], ecx
1373
	mov	[eax + SOCKET.Number], ecx
1381
	DEBUGF	1, "SOCKET_alloc: number=%u\n", ecx
1374
	DEBUGF	1, "SOCKET_alloc: number=%u\n", ecx
Line 1382... Line 1375...
1382
	mov	edi, ecx
1375
	mov	edi, ecx
Line 1467... Line 1460...
1467
	DEBUGF	1, "SOCKET_free: success!\n"
1460
	DEBUGF	1, "SOCKET_free: success!\n"
Line 1468... Line 1461...
1468
 
1461
 
1469
  .error:
1462
  .error:
Line -... Line 1463...
-
 
1463
	ret
-
 
1464
 
-
 
1465
;------------------------------------
1470
	ret
1466
;
-
 
1467
; SOCKET_fork
-
 
1468
;
1471
 
1469
; Create a child socket
1472
 
1470
;
1473
; IN:  socket nr in ebx
-
 
1474
; OUT: socket nr in eax
1471
; IN:  socket nr in ebx
-
 
1472
; OUT: child socket nr in eax
1475
; preserves edx
1473
;
1476
 
1474
;-----------------------------------
Line -... Line 1475...
-
 
1475
align 4
-
 
1476
SOCKET_fork:
1477
align 4
1477
 
1478
SOCKET_fork:
1478
	DEBUGF	1,"SOCKET_fork: %x\n", ebx
1479
 
1479
 
1480
;; Exit if backlog queue is full
1480
; Exit if backlog queue is full
Line 1481... Line 1481...
1481
;        mov     ax, [ebx + TCP_SOCKET.backlog_cur]
1481
	mov	eax, [ebx + SOCKET_QUEUE_LOCATION + queue.size]
1482
;        cmp     ax, [ebx + TCP_SOCKET.backlog]
1482
	cmp	ax, [ebx + SOCKET.backlog]
1483
;        jae     .exit
1483
	jge	.fail
-
 
1484
 
-
 
1485
; Allocate new socket
-
 
1486
	call	SOCKET_alloc
-
 
1487
	jz	.fail
-
 
1488
 
-
 
1489
	push	esi ecx edi
Line 1484... Line 1490...
1484
 
1490
	push	eax
1485
; Allocate new socket
1491
	mov	esi, esp
1486
	call	SOCKET_alloc
1492
	add_to_queue (ebx + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .fail2
1487
     ;;;   jz      .fail
1493
	pop	eax
1488
 
1494
 
1489
; Copy structure from current socket to new, (including lock!)
1495
; Copy structure from current socket to new
Line 1490... Line 1496...
1490
; We start at PID to reserve the socket num, and the 2 pointers at beginning of socket
1496
; We start at PID to preserve the socket num, and the 2 pointers at beginning of socket
1491
	lea	esi, [edx + SOCKET.PID]
-
 
-
 
1497
	lea	esi, [ebx + SOCKET.PID]
1492
	lea	edi, [eax + SOCKET.PID]
1498
	lea	edi, [eax + SOCKET.PID]
1493
	mov	ecx, (TCP_SOCKET.end - SOCKET.PID + 3)/4
1499
	mov	ecx, (SOCKET_QUEUE_LOCATION - SOCKET.PID + 3)/4
Line 1494... Line -...
1494
	rep	movsd
-
 
-
 
1500
	rep	movsd
Line -... Line 1501...
-
 
1501
 
-
 
1502
	and	[eax + SOCKET.options], not SO_ACCEPTCON
-
 
1503
 
-
 
1504
	call	SOCKET_notify_owner
-
 
1505
	pop	edi ecx esi
1495
 
1506
 
Line 1496... Line 1507...
1496
;; Push pointer to new socket to queue
1507
	ret
1497
;        movzx   ecx, [ebx + TCP_SOCKET.backlog_cur]
1508