Subversion Repositories Kolibri OS

Rev

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

Rev 5594 Rev 5984
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: 5594 $
18
$Revision: 5984 $
Line 19... Line 19...
19
 
19
 
20
struct  SOCKET
20
struct  SOCKET
Line 25... Line 25...
25
 
25
 
Line 26... Line 26...
26
        mutex                   MUTEX
26
        mutex                   MUTEX
27
 
27
 
28
        PID                     dd ? ; process ID
28
        PID                     dd ?    ; process ID
29
        TID                     dd ? ; thread ID
29
        TID                     dd ?    ; thread ID
30
        Domain                  dd ? ; INET/LOCAL/..
30
        Domain                  dd ?    ; INET4/INET6/LOCAL/..
31
        Type                    dd ? ; RAW/STREAM/DGRAM
31
        Type                    dd ?    ; RAW/STREAM/DGRAM
32
        Protocol                dd ? ; ICMP/IPv4/ARP/TCP/UDP
32
        Protocol                dd ?    ; UDP/TCP/ARP/ICMP
Line 33... Line 33...
33
        errorcode               dd ?
33
        errorcode               dd ?
34
        device                  dd ? ; driver pointer, socket pointer if it's an LOCAL socket
34
        device                  dd ?    ; device pointer, paired socket pointer if it's a local socket
35
 
35
 
Line 36... Line 36...
36
        options                 dd ?
36
        options                 dd ?
37
        state                   dd ?
37
        state                   dd ?
38
        backlog                 dw ? ; how many incoming connections that can be queued
38
        backlog                 dw ?    ; number of incoming connections that can be queued
Line 45... Line 45...
45
 
45
 
Line 46... Line 46...
46
struct  IP_SOCKET               SOCKET
46
struct  IP_SOCKET               SOCKET
47
 
47
 
-
 
48
        LocalIP                 rd 4    ; network byte order
-
 
49
        RemoteIP                rd 4    ; network byte order
Line 48... Line 50...
48
        LocalIP                 rd 4 ; network byte order
50
        ttl                     db ?
Line 49... Line 51...
49
        RemoteIP                rd 4 ; network byte order
51
                                rb 3    ; align
Line 143... Line 145...
143
 
145
 
Line 144... Line 146...
144
ends
146
ends
Line 145... Line 147...
145
 
147
 
146
struct  UDP_SOCKET              IP_SOCKET
148
struct  UDP_SOCKET              IP_SOCKET
147
 
-
 
148
        LocalPort               dw ? ; network byte order
-
 
149
        RemotePort              dw ? ; network byte order
-
 
150
 
-
 
151
ends
-
 
152
 
-
 
153
 
-
 
Line 154... Line 149...
154
struct  ICMP_SOCKET             IP_SOCKET
149
 
Line 155... Line -...
155
 
-
 
156
        Identifier              dw ?
150
        LocalPort               dw ?    ; in network byte order
Line 157... Line 151...
157
 
151
        RemotePort              dw ?    ; in network byte order
158
ends
152
 
159
 
153
ends
Line 182... Line 176...
182
        data_size               dd ?
176
        data_size               dd ?
183
        buf_ptr                 dd ?
177
        buf_ptr                 dd ?
Line 184... Line 178...
184
 
178
 
Line -... Line 179...
-
 
179
ends
-
 
180
 
-
 
181
struct  socket_options
-
 
182
 
-
 
183
        level                   dd ?
-
 
184
        optname                 dd ?
-
 
185
        optlen                  dd ?
-
 
186
        optval                  dd ?
Line 185... Line 187...
185
ends
187
 
Line 186... Line 188...
186
 
188
ends
187
 
189
 
Line 194... Line 196...
194
uglobal
196
uglobal
195
align 4
197
align 4
Line 196... Line 198...
196
 
198
 
197
        net_sockets     rd 4
199
        net_sockets     rd 4
198
        last_socket_num dd ?
200
        last_socket_num dd ?
199
        last_UDP_port   dw ? ; These values give the number of the last used ephemeral port
201
        last_UDP_port   dw ?            ; last used ephemeral port
200
        last_TCP_port   dw ? ;
202
        last_TCP_port   dw ?            ;
Line 201... Line 203...
201
        socket_mutex    MUTEX
203
        socket_mutex    MUTEX
Line 202... Line 204...
202
 
204
 
203
endg
-
 
-
 
205
endg
204
 
206
 
205
 
-
 
-
 
207
 
206
;-----------------------------------------------------------------
208
;-----------------------------------------------------------------;
207
;
209
;                                                                 ;
Line 208... Line 210...
208
; SOCKET_init
210
; SOCKET_init                                                     ;
209
;
211
;                                                                 ;
210
;-----------------------------------------------------------------
212
;-----------------------------------------------------------------;
Line 236... Line 238...
236
        mov     ecx, socket_mutex
238
        mov     ecx, socket_mutex
237
        call    mutex_init
239
        call    mutex_init
Line 238... Line 240...
238
 
240
 
Line 239... Line 241...
239
}
241
}
240
 
-
 
-
 
242
 
241
;-----------------------------------------------------------------
243
;-----------------------------------------------------------------;
242
;
-
 
-
 
244
;                                                                 ;
243
; Socket API (function 74)
245
; Sockets API (system function 75)                                ;
244
;
246
;                                                                 ;
245
;-----------------------------------------------------------------
247
;-----------------------------------------------------------------;
Line 246... Line 248...
246
align 4
248
align 4
Line 273... Line 275...
273
        mov     dword[esp+32], -1
275
        mov     dword[esp+32], -1
274
        mov     dword[esp+20], EINVAL
276
        mov     dword[esp+20], EINVAL
Line 275... Line 277...
275
 
277
 
Line 276... Line 278...
276
        ret
278
        ret
277
 
-
 
-
 
279
 
278
;-----------------------------------------------------------------
280
;-----------------------------------------------------------------;
279
;
-
 
-
 
281
;                                                                 ;
280
; SOCKET_open
282
; SOCKET_open: Create a new socket.                               ;
281
;
283
;                                                                 ;
282
;  IN:  domain in ecx
284
;   IN: ecx = domain                                              ;
-
 
285
;       edx = type                                                ;
283
;       type in edx
286
;       esi = protocol                                            ;
284
;       protocol in esi
-
 
-
 
287
;                                                                 ;
-
 
288
;  OUT: eax = socket number                                       ;
-
 
289
;       eax = -1 on error                                         ;
285
;  OUT: eax is socket num, -1 on error
290
;       ebx = errorcode on error                                  ;
286
;
291
;                                                                 ;
287
;-----------------------------------------------------------------
292
;-----------------------------------------------------------------;
Line 288... Line 293...
288
align 4
293
align 4
Line 311... Line 316...
311
        mov     [eax + SOCKET.connect_proc], connect_notsupp
316
        mov     [eax + SOCKET.connect_proc], connect_notsupp
Line 312... Line 317...
312
 
317
 
313
        cmp     ecx, AF_INET4
318
        cmp     ecx, AF_INET4
Line -... Line 319...
-
 
319
        jne     .no_inet4
-
 
320
 
314
        jne     .no_inet4
321
        mov     [eax + IP_SOCKET.ttl], 128
315
 
322
 
Line 316... Line 323...
316
        cmp     edx, SOCK_DGRAM
323
        cmp     edx, SOCK_DGRAM
317
        je      .udp
324
        je      .udp
Line 352... Line 359...
352
 
359
 
Line 353... Line 360...
353
        jmp     .unsupported
360
        jmp     .unsupported
354
 
361
 
-
 
362
align 4
-
 
363
  .udp:
-
 
364
        push    eax
-
 
365
        init_queue (eax + SOCKET_QUEUE_LOCATION)        ; Set up data receiving queue
355
align 4
366
        pop     eax
356
  .udp:
367
 
357
        mov     [eax + SOCKET.Protocol], IP_PROTO_UDP
368
        mov     [eax + SOCKET.Protocol], IP_PROTO_UDP
358
        mov     [eax + SOCKET.snd_proc], SOCKET_send_udp
369
        mov     [eax + SOCKET.snd_proc], SOCKET_send_udp
359
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
370
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
Line 371... Line 382...
371
        ret
382
        ret
Line 372... Line 383...
372
 
383
 
373
 
384
 
-
 
385
align 4
-
 
386
  .raw_ip:
-
 
387
        push    eax
-
 
388
        init_queue (eax + SOCKET_QUEUE_LOCATION)        ; Set up data receiving queue
374
align 4
389
        pop     eax
375
  .raw_ip:
390
 
376
        mov     [eax + SOCKET.snd_proc], SOCKET_send_ip
391
        mov     [eax + SOCKET.snd_proc], SOCKET_send_ip
377
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
392
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
Line 378... Line 393...
378
        mov     [eax + SOCKET.connect_proc], IPv4_connect
393
        mov     [eax + SOCKET.connect_proc], IPv4_connect
379
        ret
394
        ret
-
 
395
 
-
 
396
 
-
 
397
align 4
-
 
398
  .raw_icmp:
380
 
399
        push    eax
381
 
400
        init_queue (eax + SOCKET_QUEUE_LOCATION)        ; Set up data receiving queue
382
align 4
401
        pop     eax
383
  .raw_icmp:
402
 
Line 395... Line 414...
395
        mov     [eax + SOCKET.snd_proc], SOCKET_send_pppoe
414
        mov     [eax + SOCKET.snd_proc], SOCKET_send_pppoe
396
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
415
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
397
        ret
416
        ret
Line 398... Line 417...
398
 
417
 
399
 
-
 
-
 
418
 
400
;-----------------------------------------------------------------
419
;-----------------------------------------------------------------;
401
;
-
 
-
 
420
;                                                                 ;
402
; SOCKET_bind
421
; SOCKET_bind: Bind to a local port.                              ;
403
;
422
;                                                                 ;
404
;  IN:  socket number in ecx
423
;   IN: ecx = socket number                                       ;
-
 
424
;       edx = pointer to sockaddr struct                          ;
405
;       pointer to sockaddr struct in edx
425
;       esi = length of sockaddr struct                           ;
406
;       length of that struct in esi
-
 
-
 
426
;                                                                 ;
-
 
427
;  OUT: eax = 0 on success                                        ;
-
 
428
;       eax = -1 on error                                         ;
407
;  OUT: 0 on success
429
;       ebx = errorcode on error                                  ;
408
;
430
;                                                                 ;
409
;-----------------------------------------------------------------
431
;-----------------------------------------------------------------;
Line 410... Line 432...
410
align 4
432
align 4
Line 411... Line 433...
411
SOCKET_bind:
433
SOCKET_bind:
-
 
434
 
412
 
435
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
Line 413... Line 436...
413
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
436
 
414
 
437
        call    SOCKET_num_to_ptr
Line 484... Line 507...
484
        ret
507
        ret
Line 485... Line 508...
485
 
508
 
486
 
-
 
-
 
509
 
487
 
510
 
488
 
-
 
-
 
511
 
489
;-----------------------------------------------------------------
512
;-----------------------------------------------------------------;
490
;
513
;                                                                 ;
491
; SOCKET_connect
514
; SOCKET_connect: Connect to the remote host.                     ;
-
 
515
;                                                                 ;
492
;
516
;   IN: ecx = socket number                                       ;
493
;  IN:  socket number in ecx
-
 
-
 
517
;       edx = pointer to sockaddr struct                          ;
-
 
518
;       esi = length of sockaddr struct                           ;
-
 
519
;                                                                 ;
494
;       pointer to sockaddr struct in edx
520
;  OUT: eax = 0 on success                                        ;
495
;       length of that struct in esi
521
;       eax = -1 on error                                         ;
496
;  OUT: 0 on success
522
;       ebx = errorcode on error                                  ;
Line 497... Line 523...
497
;
523
;                                                                 ;
Line 498... Line 524...
498
;-----------------------------------------------------------------
524
;-----------------------------------------------------------------;
-
 
525
align 4
499
align 4
526
SOCKET_connect:
Line 500... Line 527...
500
SOCKET_connect:
527
 
501
 
528
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_connect: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
Line 541... Line 568...
541
        dec     eax
568
        dec     eax
542
        mov     ebx, EOPNOTSUPP
569
        mov     ebx, EOPNOTSUPP
543
        ret
570
        ret
Line 544... Line 571...
544
 
571
 
545
 
-
 
-
 
572
 
546
;-----------------------------------------------------------------
573
;-----------------------------------------------------------------;
547
;
-
 
-
 
574
;                                                                 ;
548
; SOCKET_listen
575
; SOCKET_listen: Listen for incoming connections.                 ;
549
;
576
;                                                                 ;
-
 
577
;   IN: ecx = socket number                                       ;
550
;  IN:  socket number in ecx
578
;       edx = backlog in edx                                      ;
551
;       backlog in edx
-
 
-
 
579
;                                                                 ;
-
 
580
;  OUT: eax = 0 on success                                        ;
-
 
581
;       eax = -1 on error                                         ;
552
;  OUT: eax is socket num, -1 on error
582
;       ebx = errorcode on error                                  ;
553
;
583
;                                                                 ;
554
;-----------------------------------------------------------------
584
;-----------------------------------------------------------------;
Line 555... Line 585...
555
align 4
585
align 4
Line 556... Line 586...
556
SOCKET_listen:
586
SOCKET_listen:
-
 
587
 
557
 
588
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx
Line 558... Line 589...
558
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx
589
 
559
 
590
        call    SOCKET_num_to_ptr
Line 606... Line 637...
606
        mov     dword[esp+20], EALREADY
637
        mov     dword[esp+20], EALREADY
607
        mov     dword[esp+32], -1
638
        mov     dword[esp+32], -1
608
        ret
639
        ret
Line 609... Line 640...
609
 
640
 
610
 
-
 
-
 
641
 
611
;-----------------------------------------------------------------
642
;-----------------------------------------------------------------;
612
;
-
 
-
 
643
;                                                                 ;
613
; SOCKET_accept
644
; SOCKET_accept: Accept an incoming connection.                   ;
614
;
645
;                                                                 ;
615
;  IN:  socket number in ecx
646
;   IN: ecx = socket number (of listening socket)                 ;
-
 
647
;       edx = ptr to sockaddr struct                              ;
616
;       addr in edx
648
;       esi = length of sockaddr struct                           ;
617
;       addrlen in esi
-
 
-
 
649
;                                                                 ;
-
 
650
;  OUT: eax = newly created socket num                            ;
-
 
651
;       eax = -1 on error                                         ;
618
;  OUT: eax is socket num, -1 on error
652
;       ebx = errorcode on error                                  ;
619
;
653
;                                                                 ;
620
;-----------------------------------------------------------------
654
;-----------------------------------------------------------------;
Line 621... Line 655...
621
align 4
655
align 4
Line 622... Line 656...
622
SOCKET_accept:
656
SOCKET_accept:
-
 
657
 
623
 
658
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
Line 624... Line 659...
624
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
659
 
625
 
660
        call    SOCKET_num_to_ptr
Line 639... Line 674...
639
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .block
674
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .block
Line 640... Line 675...
640
 
675
 
641
; Ok, we got a socket ptr
676
; Ok, we got a socket ptr
Line -... Line 677...
-
 
677
        mov     eax, [esi]
-
 
678
 
-
 
679
; Verify that it is (still) a valid socket
-
 
680
        call    SOCKET_check
642
        mov     eax, [esi]
681
        jz      .invalid
643
 
682
 
644
; Change thread ID to that of the current thread
683
; Change sockets thread owner ID to that of the current thread
645
        mov     ebx, [TASK_BASE]
684
        mov     ebx, [TASK_BASE]
Line 646... Line 685...
646
        mov     ebx, [ebx + TASKDATA.pid]
685
        mov     ebx, [ebx + TASKDATA.pid]
647
        mov     [eax + SOCKET.TID], ebx
-
 
648
 
686
        mov     [eax + SOCKET.TID], ebx
649
; Convert it to a socket number
-
 
650
        call    SOCKET_ptr_to_num
-
 
651
        jz      .invalid        ; FIXME ?
687
 
652
 
688
; Return socket number to caller
Line 653... Line 689...
653
; and return it to caller
689
        mov     eax, [eax + SOCKET.Number]
654
        mov     [esp+32], eax
690
        mov     [esp+32], eax
Line 674... Line 710...
674
  .notsupp:
710
  .notsupp:
675
        mov     dword[esp+20], EOPNOTSUPP
711
        mov     dword[esp+20], EOPNOTSUPP
676
        mov     dword[esp+32], -1
712
        mov     dword[esp+32], -1
677
        ret
713
        ret
Line 678... Line 714...
678
 
714
 
679
;-----------------------------------------------------------------
-
 
-
 
715
;-----------------------------------------------------------------;
680
;
716
;                                                                 ;
681
; SOCKET_close
-
 
-
 
717
; SOCKET_close: Close the socket (and connection).                ;
682
;
718
;                                                                 ;
-
 
719
;   IN: ecx = socket number                                       ;
683
;  IN:  socket number in ecx
720
;                                                                 ;
684
;  OUT: eax is socket num, -1 on error
-
 
-
 
721
;  OUT: eax = 0 on success                                        ;
-
 
722
;       eax = -1 on error                                         ;
-
 
723
;       ebx = errorcode on error                                  ;
685
;
724
;                                                                 ;
686
;-----------------------------------------------------------------
725
;-----------------------------------------------------------------;
687
align 4
726
align 4
Line 688... Line 727...
688
SOCKET_close:
727
SOCKET_close:
Line 689... Line 728...
689
 
728
 
-
 
729
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_close: socknum=%u\n", ecx
690
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_close: socknum=%u\n", ecx
730
 
Line 691... Line 731...
691
 
731
        call    SOCKET_num_to_ptr
Line 692... Line 732...
692
        call    SOCKET_num_to_ptr
732
        test    eax, eax
Line 710... Line 750...
710
  .free:
750
  .free:
711
        call    SOCKET_free
751
        call    SOCKET_free
712
        ret
752
        ret
Line 713... Line 753...
713
 
753
 
714
  .tcp:
-
 
715
 
754
  .tcp:
Line 716... Line 755...
716
        call    TCP_usrclosed
755
        call    TCP_usrclosed
717
 
756
 
718
        test    eax, eax
757
        test    eax, eax
719
        jz      @f
758
        jz      @f
720
        call    TCP_output                                      ; If connection is not closed yet, send the FIN
-
 
721
  @@:
759
        call    TCP_output                                      ; If connection is not closed yet, send the FIN
Line 722... Line 760...
722
 
760
  @@:
723
        ret
761
        ret
724
 
762
 
725
 
763
 
Line 726... Line 764...
726
  .invalid:
764
  .invalid:
727
        mov     dword[esp+20], EINVAL
-
 
-
 
765
        mov     dword[esp+20], EINVAL
728
        mov     dword[esp+32], -1
766
        mov     dword[esp+32], -1
729
        ret
-
 
-
 
767
        ret
730
 
768
 
731
 
769
 
732
;-----------------------------------------------------------------
770
;-----------------------------------------------------------------;
733
;
771
;                                                                 ;
-
 
772
; SOCKET_receive: Receive some data from the remote end.          ;
734
; SOCKET_receive
773
;                                                                 ;
735
;
-
 
-
 
774
;   IN: ecx = socket number                                       ;
-
 
775
;       edx = addr to application buffer                          ;
-
 
776
;       edx = length of application buffer                        ;
-
 
777
;       edi = flags                                               ;
736
;  IN:  socket number in ecx
778
;                                                                 ;
737
;       addr to buffer in edx
779
;  OUT: eax = number of bytes copied                              ;
738
;       length of buffer in esi
780
;       eax = -1 on error                                         ;
Line 739... Line 781...
739
;       flags in edi
781
;       eax = 0 when socket has been closed by the remote end     ;
Line 740... Line 782...
740
;  OUT: eax is number of bytes copied, -1 on error
782
;       ebx = errorcode on error                                  ;
-
 
783
;                                                                 ;
741
;
784
;-----------------------------------------------------------------;
Line 742... Line 785...
742
;-----------------------------------------------------------------
785
align 4
743
align 4
786
SOCKET_receive:
744
SOCKET_receive:
787
 
Line 760... Line 803...
760
        jne     .return
803
        jne     .return
Line 761... Line 804...
761
 
804
 
762
        test    edi, MSG_DONTWAIT
805
        test    edi, MSG_DONTWAIT
Line 763... Line 806...
763
        jnz     .return_err
806
        jnz     .return_err
764
 
807
 
Line 765... Line 808...
765
;        test    [eax + SOCKET.options], SO_NONBLOCK
808
        test    [eax + SOCKET.options], SO_NONBLOCK
766
;        jnz     .return_err
809
        jnz     .return_err
Line 780... Line 823...
780
        ret
823
        ret
Line 781... Line 824...
781
 
824
 
782
  .last_data:
825
  .last_data:
783
        test    ecx, ecx
826
        test    ecx, ecx
784
        jz      .return
827
        jz      .return
785
        call    SOCKET_notify
828
        call    SOCKET_notify                                   ; Call me again!
Line 786... Line 829...
786
        jmp     .return
829
        jmp     .return
787
 
830
 
Line 788... Line 831...
788
 
831
 
Line -... Line 832...
-
 
832
 
-
 
833
 
-
 
834
align 4
789
 
835
SOCKET_receive_dgram:
Line 790... Line 836...
790
 
836
 
791
align 4
837
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: DGRAM\n"
792
SOCKET_receive_dgram:
838
 
Line 822... Line 868...
822
        rep movsd
868
        rep movsd
823
  .nd:
869
  .nd:
Line 824... Line 870...
824
 
870
 
825
        call    NET_BUFF_free
871
        call    NET_BUFF_free
-
 
872
        pop     ecx eax                                         ; return number of bytes copied to application
826
        pop     ecx eax                                         ; return number of bytes copied to application
873
        cmp     [eax + SOCKET_QUEUE_LOCATION + queue.size], 0
-
 
874
        je      @f
-
 
875
        call    SOCKET_notify                                   ; Queue another network event
-
 
876
  @@:
827
        xor     ebx, ebx
877
        xor     ebx, ebx                                        ; errorcode = 0 (no error)
Line 828... Line 878...
828
        ret
878
        ret
829
 
879
 
830
  .too_small:
880
  .too_small:
Line 836... Line 886...
836
  .wouldblock:
886
  .wouldblock:
837
        push    EWOULDBLOCK
887
        push    EWOULDBLOCK
838
        pop     ebx
888
        pop     ebx
839
        ret
889
        ret
Line -... Line 890...
-
 
890
 
-
 
891
  .peek:
-
 
892
        xor     ebx, ebx
-
 
893
        xor     ecx, ecx
-
 
894
        cmp     [eax + SOCKET_QUEUE_LOCATION + queue.size], 0
-
 
895
        je      @f
-
 
896
        mov     esi, [eax + SOCKET_QUEUE_LOCATION + queue.r_ptr]
-
 
897
        mov     ecx, [esi + socket_queue_entry.data_size]
-
 
898
  @@:
Line 840... Line 899...
840
 
899
        ret
841
 
900
 
Line 899... Line 958...
899
        mov     ecx, [eax + STREAM_SOCKET.rcv + RING_BUFFER.size]
958
        mov     ecx, [eax + STREAM_SOCKET.rcv + RING_BUFFER.size]
900
        xor     ebx, ebx
959
        xor     ebx, ebx
901
        ret
960
        ret
Line 902... Line 961...
902
 
961
 
903
 
-
 
-
 
962
 
904
;-----------------------------------------------------------------
963
;-----------------------------------------------------------------;
905
;
-
 
906
; SOCKET_send
-
 
-
 
964
;                                                                 ;
907
;
965
; SOCKET_send: Send some data to the remote end.                  ;
908
;
966
;                                                                 ;
909
;  IN:  socket number in ecx
967
;   IN: ecx = socket number                                       ;
910
;       pointer to data in edx
968
;       edx = pointer to data                                     ;
-
 
969
;       esi = data length                                         ;
-
 
970
;       edi = flags                                               ;
911
;       datalength in esi
971
;                                                                 ;
912
;       flags in edi
-
 
-
 
972
;  OUT: eax = number of bytes sent                                ;
-
 
973
;       eax = -1 on error                                         ;
913
;  OUT: -1 on error
974
;       ebx = errorcode on error                                  ;
914
;
975
;                                                                 ;
915
;-----------------------------------------------------------------
976
;-----------------------------------------------------------------;
Line 916... Line 977...
916
align 4
977
align 4
Line 917... Line 978...
917
SOCKET_send:
978
SOCKET_send:
-
 
979
 
918
 
980
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi
Line 919... Line 981...
919
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi
981
 
920
 
982
        call    SOCKET_num_to_ptr
Line 973... Line 1035...
973
SOCKET_send_ip:
1035
SOCKET_send_ip:
Line 974... Line 1036...
974
 
1036
 
Line 975... Line 1037...
975
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: IPv4\n"
1037
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: IPv4\n"
976
 
1038
 
977
        mov     [esp+32], ecx
1039
        mov     [esp+32], ecx
978
        call    IPv4_output_raw         ; FIXME: IPv4_output_raw should return error codes!
1040
        call    IPv4_output_raw
979
        cmp     eax, -1
1041
        cmp     eax, -1
Line 980... Line 1042...
980
        je      .error
1042
        je      .error
981
        ret
1043
        ret
982
 
1044
 
983
  .error:
1045
  .error:
Line 984... Line 1046...
984
        mov     dword[esp+32], -1
1046
        mov     dword[esp+32], eax
985
        mov     dword[esp+20], EMSGSIZE
1047
        mov     dword[esp+20], ebx
Line 986... Line 1048...
986
        ret
1048
        ret
Line 987... Line 1049...
987
 
1049
 
988
 
1050
 
989
align 4
1051
align 4
990
SOCKET_send_icmp:
1052
SOCKET_send_icmp:
991
 
1053
 
Line 992... Line 1054...
992
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: ICMP\n"
1054
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_send: ICMP\n"
993
 
1055
 
994
        mov     [esp+32], ecx
1056
        mov     [esp+32], ecx
995
        call    ICMP_output_raw         ; FIXME: errorcodes
1057
        call    ICMP_output_raw
Line 996... Line 1058...
996
        cmp     eax, -1
1058
        cmp     eax, -1
997
        je      .error
1059
        je      .error
Line 1066... Line 1128...
1066
        mov     dword[esp+32], -1
1128
        mov     dword[esp+32], -1
1067
        mov     dword[esp+20], EINVAL
1129
        mov     dword[esp+20], EINVAL
1068
        ret
1130
        ret
Line 1069... Line 1131...
1069
 
1131
 
1070
 
-
 
-
 
1132
 
1071
;-----------------------------------------------------------------
1133
;-----------------------------------------------------------------;
1072
;
-
 
-
 
1134
;                                                                 ;
1073
; SOCKET_get_options
1135
; SOCKET_get_options: Read a socket option                        ;
1074
;
1136
;                                                                 ;
-
 
1137
;   IN: ecx = socket number                                       ;
-
 
1138
;       edx = pointer to socket options struct                    ;
-
 
1139
;                                                                 ;
-
 
1140
;  OUT: eax = 0 on success                                        ;
1075
;  IN:  ecx = socket number
1141
;       eax = -1 on error                                         ;
-
 
1142
;       ebx = errorcode on error                                  ;
-
 
1143
;                                                                 ;
1076
;       edx = pointer to the options:
1144
;-----------------------------------------------------------------;
1077
;               dd      level, optname, optval, optlen
1145
align 4
-
 
1146
SOCKET_get_opt:
1078
;  OUT: -1 on error
1147
 
1079
;
1148
; FIXME:
1080
; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP.
1149
; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP.
1081
; TODO: find best way to notify that send()'ed data were acknowledged
-
 
1082
; Also pseudo-optname -3 is valid and returns socket state, one of TCPS_*.
-
 
1083
;
-
 
1084
;-----------------------------------------------------------------
-
 
Line 1085... Line 1150...
1085
align 4
1150
; TODO: find best way to notify that send()'ed data were acknowledged
Line 1086... Line 1151...
1086
SOCKET_get_opt:
1151
; Also pseudo-optname -3 is valid and returns socket state, one of TCPS_*.
-
 
1152
 
1087
 
1153
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_get_opt\n"
Line 1088... Line 1154...
1088
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_get_opt\n"
1154
 
1089
 
1155
        call    SOCKET_num_to_ptr
1090
        call    SOCKET_num_to_ptr
1156
        test    eax, eax
Line 1124... Line 1190...
1124
        mov     dword[esp+32], -1
1190
        mov     dword[esp+32], -1
1125
        mov     dword[esp+20], EINVAL
1191
        mov     dword[esp+20], EINVAL
1126
        ret
1192
        ret
Line 1127... Line -...
1127
 
-
 
1128
 
1193
 
1129
 
-
 
-
 
1194
 
1130
;-----------------------------------------------------------------
1195
;-----------------------------------------------------------------;
1131
;
-
 
-
 
1196
;                                                                 ;
1132
; SOCKET_set_options
1197
; SOCKET_set_options: Set a socket option.                        ;
1133
;
1198
;                                                                 ;
1134
;  IN:  ecx = socket number
1199
;   IN: ecx = socket number                                       ;
-
 
1200
;       edx = pointer to socket options struct                    ;
1135
;       edx = pointer to the options:
1201
;                                                                 ;
1136
;               dd      level, optname, optlen, optval
-
 
-
 
1202
;  OUT: eax = 0 on success                                        ;
-
 
1203
;       eax = -1 on error                                         ;
1137
;  OUT: -1 on error
1204
;       ebx = errorcode on error                                  ;
1138
;
1205
;                                                                 ;
1139
;-----------------------------------------------------------------
1206
;-----------------------------------------------------------------;
Line 1140... Line 1207...
1140
align 4
1207
align 4
Line 1141... Line 1208...
1141
SOCKET_set_opt:
1208
SOCKET_set_opt:
-
 
1209
 
1142
 
1210
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_set_opt\n"
Line -... Line 1211...
-
 
1211
 
-
 
1212
        call    SOCKET_num_to_ptr
1143
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_set_opt\n"
1213
        test    eax, eax
1144
 
1214
        jz      .invalid
Line 1145... Line -...
1145
        call    SOCKET_num_to_ptr
-
 
1146
        jz      .invalid
-
 
1147
 
-
 
1148
        cmp     dword [edx], SOL_SOCKET
1215
 
1149
        jne     .invalid
-
 
1150
 
1216
        cmp     [edx + socket_options.level], IP_PROTO_IP
1151
        cmp     dword [edx+4], SO_BINDTODEVICE
1217
        je      .ip
Line 1152... Line 1218...
1152
        je      .bind
1218
        cmp     [edx + socket_options.level], SOL_SOCKET
1153
 
1219
        jne     .invalid
1154
  .invalid:
1220
 
Line 1155... Line 1221...
1155
        mov     dword[esp+32], -1
1221
  .socket:
1156
        mov     dword[esp+20], EINVAL
1222
        cmp     [edx + socket_options.optname], SO_BINDTODEVICE
1157
        ret
1223
        jne     .invalid
Line 1158... Line 1224...
1158
 
1224
 
1159
  .bind:
1225
  .bind:
Line 1178... Line 1244...
1178
        mov     [eax + SOCKET.device], 0
1244
        mov     [eax + SOCKET.device], 0
Line 1179... Line 1245...
1179
 
1245
 
1180
        mov     dword[esp+32], 0        ; success!
1246
        mov     dword[esp+32], 0        ; success!
Line -... Line 1247...
-
 
1247
        ret
-
 
1248
 
-
 
1249
  .ip:
-
 
1250
        cmp     [edx + socket_options.optname], IP_TTL
-
 
1251
        jne     .invalid
-
 
1252
 
-
 
1253
  .ttl:
-
 
1254
        mov     bl, byte[edx + socket_options.optval]
-
 
1255
        mov     [eax + IP_SOCKET.ttl], bl
-
 
1256
 
-
 
1257
        mov     dword[esp+32], 0        ; success!
1181
        ret
1258
        ret
1182
 
1259
 
1183
  .already:
1260
  .already:
1184
        mov     dword[esp+20], EALREADY
1261
        mov     dword[esp+20], EALREADY
Line -... Line 1262...
-
 
1262
        mov     dword[esp+32], -1
-
 
1263
        ret
-
 
1264
 
-
 
1265
  .invalid:
Line -... Line 1266...
-
 
1266
        mov     dword[esp+20], EINVAL
1185
        mov     dword[esp+32], -1
1267
        mov     dword[esp+32], -1
1186
        ret
-
 
1187
 
1268
        ret
1188
 
-
 
1189
 
1269
 
1190
 
-
 
-
 
1270
 
1191
;-----------------------------------------------------------------
1271
 
-
 
1272
 
1192
;
1273
;-----------------------------------------------------------------;
-
 
1274
;                                                                 ;
1193
; SOCKET_pair
1275
; SOCKET_pair: Allocate a pair of linked local sockets.           ;
1194
;
-
 
-
 
1276
;                                                                 ;
-
 
1277
;  IN: /                                                          ;
1195
; Allocates a pair of linked LOCAL domain sockets
1278
;                                                                 ;
1196
;
1279
; OUT: eax = socket1 num on success                               ;
1197
; IN: /
1280
;      eax = -1 on error                                          ;
Line 1198... Line 1281...
1198
; OUT: eax is socket1 num, -1 on error
1281
;      ebx = socket2 num on success                               ;
Line 1234... Line 1317...
1234
        mov     [ebx + SOCKET.device], eax
1317
        mov     [ebx + SOCKET.device], eax
Line 1235... Line 1318...
1235
 
1318
 
1236
        lea     eax, [eax + STREAM_SOCKET.rcv]
1319
        lea     eax, [eax + STREAM_SOCKET.rcv]
1237
        call    SOCKET_ring_create
1320
        call    SOCKET_ring_create
1238
        test    eax, eax
1321
        test    eax, eax
Line 1239... Line 1322...
1239
        jz      .nomem1
1322
        jz      .nomem2
1240
 
1323
 
1241
        lea     eax, [ebx + STREAM_SOCKET.rcv]
1324
        lea     eax, [ebx + STREAM_SOCKET.rcv]
1242
        call    SOCKET_ring_create
1325
        call    SOCKET_ring_create
Line 1243... Line 1326...
1243
        test    eax, eax
1326
        test    eax, eax
Line 1244... Line 1327...
1244
        jz      .nomem2
1327
        jz      .nomem2
1245
 
1328
 
1246
        ret
1329
        ret
-
 
1330
 
1247
 
1331
  .nomem2:
-
 
1332
        mov     eax, [esp+20]
-
 
1333
        call    SOCKET_free
-
 
1334
 
1248
  .nomem2:
1335
  .nomem1:
1249
        mov     eax, ebx
1336
        mov     eax, [esp+32]
1250
        call    SOCKET_free
1337
        call    SOCKET_free
Line 1251... Line 1338...
1251
  .nomem1:
1338
 
1252
        mov     dword[esp+32], -1
-
 
1253
        mov     dword[esp+28], ENOMEM
1339
        mov     dword[esp+32], -1
1254
        ret
-
 
1255
 
1340
        mov     dword[esp+20], ENOMEM
1256
 
-
 
-
 
1341
        ret
1257
 
1342
 
1258
;-----------------------------------------------------------------
1343
 
1259
;
-
 
-
 
1344
 
-
 
1345
;-----------------------------------------------------------------;
1260
; SOCKET_debug
1346
;                                                                 ;
-
 
1347
; SOCKET_debug: Copy socket variables to application buffer.      ;
-
 
1348
;                                                                 ;
1261
;
1349
;   IN: ecx = socket number                                       ;
1262
;  Copies socket variables to application buffer
1350
;       edx = pointer to application buffer                       ;
1263
;
1351
;                                                                 ;
Line 1264... Line 1352...
1264
;  IN:  ecx = socket number
1352
;  OUT: eax = 0 on success                                        ;
Line 1275... Line 1363...
1275
 
1363
 
1276
        test    ecx, ecx
1364
        test    ecx, ecx
Line 1277... Line 1365...
1277
        jz      .returnall
1365
        jz      .returnall
-
 
1366
 
1278
 
1367
        call    SOCKET_num_to_ptr
Line 1279... Line 1368...
1279
        call    SOCKET_num_to_ptr
1368
        test    eax, eax
1280
        jz      .invalid
1369
        jz      .invalid
1281
 
1370
 
Line 1301... Line 1390...
1301
        mov     dword[esp+32], eax
1390
        mov     dword[esp+32], eax
1302
        ret
1391
        ret
Line 1303... Line 1392...
1303
 
1392
 
1304
  .invalid:
1393
  .invalid:
1305
        mov     dword[esp+32], -1
1394
        mov     dword[esp+32], -1
1306
        mov     dword[esp+28], EINVAL
1395
        mov     dword[esp+20], EINVAL
Line 1307... Line 1396...
1307
        ret
1396
        ret
-
 
1397
 
-
 
1398
 
-
 
1399
;-----------------------------------------------------------------;
-
 
1400
;   ____                                                 ____     ;
-
 
1401
;   \  /              End of sockets API                 \  /     ;
-
 
1402
;    \/                                                   \/      ;
1308
 
1403
;    ()        Internally used functions follow           ()      ;
1309
 
-
 
1310
;-----------------------------------------------------------------
1404
;                                                                 ;
-
 
1405
;-----------------------------------------------------------------;
-
 
1406
 
-
 
1407
 
1311
;
1408
;-----------------------------------------------------------------;
1312
; SOCKET_find_port
1409
;                                                                 ;
1313
;
1410
; SOCKET_find_port:                                               ;
1314
; Fills in the local port number for TCP and UDP sockets
-
 
-
 
1411
; Fill in the local port number for TCP and UDP sockets           ;
1315
; This procedure always works because the number of sockets is
1412
; This procedure always works because the number of sockets is    ;
-
 
1413
; limited to a smaller number then the number of possible ports   ;
1316
; limited to a smaller number then the number of possible ports
1414
;                                                                 ;
1317
;
-
 
-
 
1415
;  IN:  eax = socket pointer                                      ;
1318
;  IN:  eax = socket pointer
1416
;                                                                 ;
1319
;  OUT: /
1417
;  OUT: /                                                         ;
1320
;
1418
;                                                                 ;
Line 1321... Line 1419...
1321
;-----------------------------------------------------------------
1419
;-----------------------------------------------------------------;
Line 1365... Line 1463...
1365
        jz      .findit
1463
        jz      .findit
1366
        ret
1464
        ret
Line 1367... Line 1465...
1367
 
1465
 
1368
 
-
 
-
 
1466
 
1369
 
1467
 
1370
;-----------------------------------------------------------------
-
 
-
 
1468
;-----------------------------------------------------------------;
1371
;
1469
;                                                                 ;
1372
; SOCKET_check_port (to be used with AF_INET only!)
1470
; SOCKET_check_port (to be used with AF_INET only!)               ;
1373
;
-
 
-
 
1471
;                                                                 ;
-
 
1472
; Checks if a local port number is unused                         ;
1374
; Checks if a local port number is unused
1473
; If the proposed port number is unused, it is filled in in the   ;
1375
; If the proposed port number is unused, it is filled in in the socket structure
1474
; socket structure                                                ;
1376
;
-
 
-
 
1475
;                                                                 ;
1377
;  IN:  eax = socket ptr (to find out if its a TCP/UDP socket)
1476
;   IN: eax = socket ptr                                          ;
1378
;        bx = proposed socket number (network byte order)
-
 
-
 
1477
;       bx = proposed socket number (network byte order)          ;
1379
;
1478
;                                                                 ;
1380
;  OUT:  ZF = set on error
1479
;  OUT: ZF = set on error                                         ;
1381
;
1480
;                                                                 ;
Line 1382... Line 1481...
1382
;-----------------------------------------------------------------
1481
;-----------------------------------------------------------------;
Line 1427... Line 1526...
1427
        or      bx, bx                                  ; clear the zero-flag
1526
        or      bx, bx                                  ; clear the zero-flag
1428
        ret
1527
        ret
Line 1429... Line 1528...
1429
 
1528
 
1430
 
-
 
1431
 
1529
 
1432
;-----------------------------------------------------------------
-
 
1433
;
1530
 
1434
; SOCKET_input
-
 
-
 
1531
;-----------------------------------------------------------------;
1435
;
1532
;                                                                 ;
1436
; Updates a (stateless) socket with received data
-
 
-
 
1533
; SOCKET_input: Update a (stateless) socket with received data.   ;
1437
;
1534
;                                                                 ;
1438
; Note: the mutex should already be set !
1535
; Note: The socket's mutex should already be set !                ;
1439
;
1536
;                                                                 ;
1440
;  IN:  eax = socket ptr
1537
;   IN: eax = socket ptr                                          ;
1441
;       ecx = data size
-
 
-
 
1538
;       ecx = data size                                           ;
1442
;       esi = ptr to data
1539
;       esi = ptr to data                                         ;
1443
;       [esp] = ptr to buf
-
 
-
 
1540
;       [esp] = ptr to buf                                        ;
1444
;
1541
;                                                                 ;
1445
;  OUT: /
1542
;  OUT: /                                                         ;
1446
;
1543
;                                                                 ;
Line 1447... Line 1544...
1447
;-----------------------------------------------------------------
1544
;-----------------------------------------------------------------;
Line 1472... Line 1569...
1472
        pusha
1569
        pusha
1473
        lea     ecx, [eax + SOCKET.mutex]
1570
        lea     ecx, [eax + SOCKET.mutex]
1474
        call    mutex_unlock
1571
        call    mutex_unlock
1475
        popa
1572
        popa
Line -... Line 1573...
-
 
1573
 
1476
 
1574
        add     esp, 8
1477
        call    NET_BUFF_free
1575
        call    NET_BUFF_free
Line 1478... Line 1576...
1478
        ret
1576
        ret
1479
 
-
 
-
 
1577
 
-
 
1578
 
-
 
1579
;-----------------------------------------------------------------;
1480
 
1580
;                                                                 ;
1481
;--------------------------
-
 
-
 
1581
; SOCKET_ring_create: Create a ringbuffer for sockets.            ;
-
 
1582
;                                                                 ;
-
 
1583
;   IN: eax = ptr to ring struct                                  ;
-
 
1584
;                                                                 ;
-
 
1585
;  OUT: eax = 0 on error                                          ;
1482
;
1586
;       eax = start ptr                                           ;
1483
; eax = ptr to ring struct (just a buffer of the right size)
1587
;                                                                 ;
Line 1484... Line 1588...
1484
;
1588
;-----------------------------------------------------------------;
1485
align 4
1589
align 4
Line 1492... Line 1596...
1492
        stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SWR
1596
        stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SWR
1493
        pop     edx
1597
        pop     edx
1494
        test    eax, eax
1598
        test    eax, eax
1495
        jz      .fail
1599
        jz      .fail
Line 1496... Line 1600...
1496
 
1600
 
Line 1497... Line 1601...
1497
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_ring_created: %x\n", eax
1601
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_ring_create: %x\n", eax
1498
 
1602
 
1499
        pusha
1603
        pusha
1500
        lea     ecx, [esi + RING_BUFFER.mutex]
1604
        lea     ecx, [esi + RING_BUFFER.mutex]
Line 1507... Line 1611...
1507
        mov     [esi + RING_BUFFER.size], 0
1611
        mov     [esi + RING_BUFFER.size], 0
1508
        add     eax, SOCKET_MAXDATA
1612
        add     eax, SOCKET_MAXDATA
1509
        mov     [esi + RING_BUFFER.end_ptr], eax
1613
        mov     [esi + RING_BUFFER.end_ptr], eax
1510
        mov     eax, esi
1614
        mov     eax, esi
Line -... Line 1615...
-
 
1615
 
-
 
1616
        pop     esi
-
 
1617
        ret
1511
 
1618
 
-
 
1619
  .fail:
1512
  .fail:
1620
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_ring_create: Out of memory!\n"
1513
        pop     esi
1621
        pop     esi
Line 1514... Line 1622...
1514
        ret
1622
        ret
1515
 
-
 
-
 
1623
 
1516
;-----------------------------------------------------------------
1624
;-----------------------------------------------------------------;
1517
;
-
 
1518
; SOCKET_ring_write
1625
;                                                                 ;
1519
;
-
 
1520
; Adds data to a stream socket, and updates write pointer and size
1626
; SOCKET_ring_write: Write data to ring buffer.                   ;
1521
;
1627
;                                                                 ;
1522
;  IN:  eax = ptr to ring struct
1628
;   IN: eax = ptr to ring struct                                  ;
1523
;       ecx = data size
-
 
-
 
1629
;       ecx = data size                                           ;
1524
;       esi = ptr to data
1630
;       esi = ptr to data                                         ;
1525
;
-
 
-
 
1631
;                                                                 ;
1526
;  OUT: ecx = number of bytes stored
1632
;  OUT: ecx = number of bytes stored                              ;
1527
;
1633
;                                                                 ;
1528
;-----------------------------------------------------------------
1634
;-----------------------------------------------------------------;
Line 1529... Line 1635...
1529
align 4
1635
align 4
Line 1583... Line 1689...
1583
        call    mutex_unlock                                    ; TODO: check what registers this function actually destroys
1689
        call    mutex_unlock                                    ; TODO: check what registers this function actually destroys
1584
        popa
1690
        popa
Line 1585... Line 1691...
1585
 
1691
 
Line 1586... Line 1692...
1586
        ret
1692
        ret
1587
 
-
 
-
 
1693
 
1588
;-----------------------------------------------------------------
1694
;-----------------------------------------------------------------;
1589
;
-
 
-
 
1695
;                                                                 ;
1590
; SOCKET_ring_read
1696
; SOCKET_ring_read: Read from ring buffer                         ;
1591
;
1697
;                                                                 ;
1592
;  IN:  eax = ring struct ptr
1698
;   IN: eax = ring struct ptr                                     ;
1593
;       ecx = bytes to read
1699
;       ecx = bytes to read                                       ;
1594
;       edx = offset
-
 
-
 
1700
;       edx = offset                                              ;
1595
;       edi = ptr to buffer start
1701
;       edi = ptr to buffer start                                 ;
1596
;
1702
;                                                                 ;
1597
;  OUT: eax = unchanged
1703
;  OUT: eax = unchanged                                           ;
1598
;       ecx = number of bytes read (0 on error)
1704
;       ecx = number of bytes read (0 on error)                   ;
1599
;       edx = destroyed
1705
;       edx = destroyed                                           ;
1600
;       esi = destroyed
-
 
-
 
1706
;       esi = destroyed                                           ;
1601
;       edi = ptr to buffer end
1707
;       edi = ptr to buffer end                                   ;
1602
;
1708
;                                                                 ;
1603
;-----------------------------------------------------------------
1709
;-----------------------------------------------------------------;
Line 1604... Line 1710...
1604
align 4
1710
align 4
Line 1657... Line 1763...
1657
  .less_data:
1763
  .less_data:
1658
        mov     ecx, edx
1764
        mov     ecx, edx
1659
        jmp     .copy
1765
        jmp     .copy
Line 1660... Line 1766...
1660
 
1766
 
1661
 
-
 
-
 
1767
 
1662
;-----------------------------------------------------------------
1768
;-----------------------------------------------------------------;
1663
;
-
 
1664
; SOCKET_ring_free
1769
;                                                                 ;
1665
;
-
 
1666
; Free's some bytes from the ringbuffer
1770
; SOCKET_ring_free: Free data from a ringbuffer                   ;
1667
;
1771
;                                                                 ;
1668
;  IN:  eax = ptr to ring struct
-
 
-
 
1772
;   IN: eax = ptr to ring struct                                  ;
1669
;       ecx = data size
1773
;       ecx = data size                                           ;
1670
;
-
 
-
 
1774
;                                                                 ;
1671
;  OUT: ecx = number of bytes free-ed
1775
;  OUT: ecx = number of freed bytes                               ;
1672
;
1776
;                                                                 ;
1673
;-----------------------------------------------------------------
1777
;-----------------------------------------------------------------;
Line 1674... Line 1778...
1674
align 4
1778
align 4
Line 1709... Line 1813...
1709
 
1813
 
1710
        xor     ecx, ecx
1814
        xor     ecx, ecx
Line 1711... Line 1815...
1711
        ret
1815
        ret
1712
 
-
 
1713
 
1816
 
1714
;-----------------------------------------------------------------
-
 
1715
;
1817
 
1716
; SOCKET_block
-
 
-
 
1818
;-----------------------------------------------------------------;
1717
;
1819
;                                                                 ;
-
 
1820
; SOCKET_block: Suspend the thread attached to a socket.          ;
1718
; Suspends the thread attached to a socket
1821
;                                                                 ;
1719
;
-
 
-
 
1822
;   IN: eax = socket ptr                                          ;
1720
;  IN:  eax = socket ptr
1823
;                                                                 ;
1721
;  OUT: eax = unchanged
1824
;  OUT: eax = unchanged                                           ;
1722
;
1825
;                                                                 ;
Line 1723... Line 1826...
1723
;-----------------------------------------------------------------
1826
;-----------------------------------------------------------------;
Line 1752... Line 1855...
1752
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_block: continuing\n"
1855
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_block: continuing\n"
Line 1753... Line 1856...
1753
 
1856
 
Line 1754... Line 1857...
1754
        ret
1857
        ret
1755
 
-
 
-
 
1858
 
1756
 
1859
 
1757
;-----------------------------------------------------------------
-
 
1758
;
1860
;-----------------------------------------------------------------;
1759
; SOCKET_notify
-
 
1760
;
1861
;                                                                 ;
-
 
1862
; SOCKET_notify: Wake up socket owner thread.                     ;
1761
; notify's the owner of a socket that something happened
1863
;                                                                 ;
1762
;
-
 
-
 
1864
;   IN: eax = socket ptr                                          ;
1763
;  IN:  eax = socket ptr
1865
;                                                                 ;
1764
;  OUT: eax = unchanged
1866
;  OUT: eax = unchanged                                           ;
1765
;
1867
;                                                                 ;
Line 1766... Line 1868...
1766
;-----------------------------------------------------------------
1868
;-----------------------------------------------------------------;
Line 1800... Line 1902...
1800
 
1902
 
1801
  .found:
1903
  .found:
1802
        test    [eax + SOCKET.state], SS_BLOCKED
1904
        test    [eax + SOCKET.state], SS_BLOCKED
Line 1803... Line 1905...
1803
        jnz     .un_block
1905
        jnz     .un_block
1804
 
1906
 
1805
; socket and thread exists and socket is of non blocking type.
1907
; Socket and thread exists and socket is of non blocking type.
1806
; We'll try to flag an event to the thread.
1908
; We'll try to flag an event to the thread.
Line 1807... Line 1909...
1807
        shl     ecx, 8
1909
        shl     ecx, 8
1808
        or      [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
1910
        or      [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
1809
 
1911
 
Line 1810... Line 1912...
1810
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: poking thread %u!\n", eax
1912
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: poking thread %u!\n", eax
1811
        pop     esi ecx ebx
1913
        pop     esi ecx ebx
1812
        ret
1914
        ret
1813
 
1915
 
1814
 
1916
 
Line 1815... Line 1917...
1815
  .un_block:
1917
  .un_block:
1816
; socket and thread exists and socket is of blocking type
1918
; Socket and thread exists and socket is of blocking type
1817
; We'll try to unblock it.
1919
; We'll try to unblock it.
Line 1818... Line 1920...
1818
        and     [eax + SOCKET.state], not SS_BLOCKED    ; Clear the 'socket is blocked' flag
1920
        and     [eax + SOCKET.state], not SS_BLOCKED    ; Clear the 'socket is blocked' flag
1819
        mov     [esi + TASKDATA.state], 0               ; Run the thread
-
 
-
 
1921
        mov     [esi + TASKDATA.state], 0               ; Run the thread
1820
 
1922
 
1821
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: Unblocked socket!\n"
-
 
1822
        pop     esi ecx ebx
1923
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: Unblocked socket!\n"
1823
        ret
1924
        pop     esi ecx ebx
1824
 
1925
        ret
1825
 
-
 
-
 
1926
 
1826
;--------------------------------------------------------------------
1927
 
-
 
1928
;-----------------------------------------------------------------;
-
 
1929
;                                                                 ;
1827
;
1930
; SOCKET_alloc:                                                   ;
1828
; SOCKET_alloc
1931
; Allocate memory for socket and put new socket into the list.    ;
1829
;
-
 
-
 
1932
; Newly created socket is initialized with calling PID and socket ;
1830
; Allocate memory for socket data and put new socket into the list
1933
; number.                                                         ;
1831
; Newly created socket is initialized with calling PID and number and
1934
;                                                                 ;
1832
; put into beginning of list (which is a fastest way).
1935
;  IN:  /                                                         ;
Line 1833... Line 1936...
1833
;
1936
;                                                                 ;
Line 1834... Line 1937...
1834
; IN:  /
1937
; OUT:  eax = socket ptr on success                               ;
1835
; OUT: eax = 0 on error, socket ptr otherwise
-
 
1836
;      edi = socket number
1938
;       eax = 0 on error                                          ;
1837
;
1939
;       edi = socket number on success                            ;
-
 
1940
;                                                                 ;
Line 1838... Line 1941...
1838
;--------------------------------------------------------------------
1941
;-----------------------------------------------------------------;
1839
align 4
1942
align 4
1840
SOCKET_alloc:
1943
SOCKET_alloc:
1841
 
1944
 
Line 1923... Line 2026...
1923
 
2026
 
1924
        pusha
2027
        pusha
1925
        mov     ecx, socket_mutex
2028
        mov     ecx, socket_mutex
1926
        call    mutex_unlock
2029
        call    mutex_unlock
1927
        popa
-
 
1928
 
-
 
1929
  .exit:
2030
        popa
Line 1930... Line 2031...
1930
        pop     ebx
2031
        pop     ebx
Line -... Line 2032...
-
 
2032
 
-
 
2033
        ret
-
 
2034
 
-
 
2035
  .nomem:
-
 
2036
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_alloc: Out of memory!\n"
1931
 
2037
        pop     ebx
1932
        ret
2038
        ret
1933
 
2039
 
1934
  .not_yet:
2040
  .not_yet:
Line 1935... Line 2041...
1935
        mov     dword[esp+20], ENOTCONN
2041
        mov     dword[esp+20], ENOTCONN
1936
        mov     dword[esp+32], -1
-
 
-
 
2042
        mov     dword[esp+32], -1
1937
        ret
2043
        ret
1938
 
-
 
1939
 
2044
 
1940
;----------------------------------------------------
2045
 
1941
;
-
 
-
 
2046
;-----------------------------------------------------------------;
1942
; SOCKET_free
2047
;                                                                 ;
-
 
2048
; SOCKET_free:                                                    ;
1943
;
2049
; Free socket data memory and remove socket from the list.        ;
1944
; Free socket data memory and remove socket from the list
-
 
-
 
2050
; Caller should lock and unlock socket_mutex.                     ;
1945
; Caller should lock and unlock socket_mutex
2051
;                                                                 ;
1946
;
2052
;  IN:  eax = socket ptr                                          ;
1947
; IN:  eax = socket ptr
2053
;                                                                 ;
Line 1948... Line 2054...
1948
; OUT: /
2054
; OUT:  /                                                         ;
Line 1961... Line 2067...
1961
        pusha
2067
        pusha
1962
        lea     ecx, [eax + SOCKET.mutex]
2068
        lea     ecx, [eax + SOCKET.mutex]
1963
        call    mutex_lock
2069
        call    mutex_lock
1964
        popa
2070
        popa
Line 1965... Line 2071...
1965
 
2071
 
1966
        cmp     [eax + SOCKET.Domain], AF_INET4
-
 
1967
        jnz     .no_tcp
-
 
1968
 
-
 
1969
        cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
2072
        cmp     [eax + SOCKET.Type], SOCK_STREAM
Line 1970... Line 2073...
1970
        jnz     .no_tcp
2073
        jne     .no_stream
-
 
2074
 
-
 
2075
        mov     ebx, eax
1971
 
2076
        cmp     [eax + STREAM_SOCKET.rcv.start_ptr], 0
-
 
2077
        je      @f
-
 
2078
        stdcall free_kernel_space, [eax + STREAM_SOCKET.rcv.start_ptr]
-
 
2079
  @@:
1972
        mov     ebx, eax
2080
        cmp     [ebx + STREAM_SOCKET.snd.start_ptr], 0
-
 
2081
        je      @f
1973
        stdcall kernel_free, [ebx + STREAM_SOCKET.rcv.start_ptr]
2082
        stdcall free_kernel_space, [ebx + STREAM_SOCKET.snd.start_ptr]
1974
        stdcall kernel_free, [ebx + STREAM_SOCKET.snd.start_ptr]
2083
  @@:
Line 1975... Line 2084...
1975
        mov     eax, ebx
2084
        mov     eax, ebx
1976
  .no_tcp:
2085
  .no_stream:
1977
 
2086
 
1978
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_free: freeing socket %x\n", eax
2087
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_free: freeing socket %x\n", eax
Line 1998... Line 2107...
1998
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_free: success!\n"
2107
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_free: success!\n"
Line 1999... Line 2108...
1999
 
2108
 
2000
  .error:
2109
  .error:
Line -... Line 2110...
-
 
2110
        ret
-
 
2111
 
2001
        ret
2112
  .error1:
2002
 
-
 
-
 
2113
        pop     ebx
2003
;------------------------------------
2114
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_free: error!\n"
2004
;
2115
        DEBUGF  DEBUG_NETWORK_ERROR, "socket ptr=0x%x caller=0x%x\n", eax, [esp]
-
 
2116
        ret
-
 
2117
 
2005
; SOCKET_fork
2118
;-----------------------------------------------------------------;
2006
;
-
 
-
 
2119
;                                                                 ;
2007
; Create a child socket
2120
; SOCKET_fork: Create a child socket.                             ;
-
 
2121
;                                                                 ;
2008
;
2122
;  IN:  ebx = socket number                                       ;
2009
; IN:  socket nr in ebx
-
 
-
 
2123
;                                                                 ;
-
 
2124
; OUT:  eax = child socket number on success                      ;
2010
; OUT: child socket nr in eax
2125
;       eax = 0 on error                                          ;
2011
;
2126
;                                                                 ;
2012
;-----------------------------------
2127
;-----------------------------------------------------------------;
Line 2013... Line 2128...
2013
align 4
2128
align 4
Line 2056... Line 2171...
2056
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_fork: failed\n"
2171
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_fork: failed\n"
2057
        xor     eax, eax
2172
        xor     eax, eax
2058
        ret
2173
        ret
Line 2059... Line 2174...
2059
 
2174
 
2060
 
-
 
2061
;---------------------------------------------------
2175
 
2062
;
-
 
2063
; SOCKET_num_to_ptr
2176
;-----------------------------------------------------------------;
2064
;
-
 
-
 
2177
;                                                                 ;
2065
; Get socket structure address by its number
2178
; SOCKET_num_to_ptr: Get socket structure address by its number.  ;
-
 
2179
;                                                                 ;
2066
;
2180
;  IN:  ecx = socket number                                       ;
2067
; IN:  ecx = socket number
2181
;                                                                 ;
2068
; OUT: eax = 0 on error, socket ptr otherwise
-
 
-
 
2182
; OUT:  eax = socket ptr                                          ;
2069
;       ZF = set on error
2183
;       eax = 0 on error                                          ;
2070
;
2184
;                                                                 ;
2071
;---------------------------------------------------
2185
;-----------------------------------------------------------------;
Line 2072... Line 2186...
2072
align 4
2186
align 4
Line 2078... Line 2192...
2078
        mov     ecx, socket_mutex
2192
        mov     ecx, socket_mutex
2079
        call    mutex_lock
2193
        call    mutex_lock
2080
        popa
2194
        popa
Line 2081... Line 2195...
2081
 
2195
 
2082
        mov     eax, net_sockets
-
 
2083
 
2196
        mov     eax, net_sockets
2084
  .next_socket:
2197
  .next_socket:
2085
        mov     eax, [eax + SOCKET.NextPtr]
2198
        mov     eax, [eax + SOCKET.NextPtr]
2086
        or      eax, eax
2199
        test    eax, eax
2087
        jz      .error
2200
        jz      .error
2088
        cmp     [eax + SOCKET.Number], ecx
2201
        cmp     [eax + SOCKET.Number], ecx
Line 2089... Line -...
2089
        jne     .next_socket
-
 
2090
 
-
 
2091
        test    eax, eax
2202
        jne     .next_socket
2092
 
2203
 
2093
        pusha
2204
        pusha
2094
        mov     ecx, socket_mutex
2205
        mov     ecx, socket_mutex
Line 2107... Line 2218...
2107
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: socket %u not found!\n", eax
2218
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: socket %u not found!\n", eax
2108
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: caller = 0x%x\n", [esp]
2219
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: caller = 0x%x\n", [esp]
2109
        ret
2220
        ret
Line 2110... Line 2221...
2110
 
2221
 
2111
 
-
 
2112
;---------------------------------------------------
2222
 
2113
;
-
 
2114
; SOCKET_ptr_to_num
2223
;-----------------------------------------------------------------;
2115
;
-
 
-
 
2224
;                                                                 ;
2116
; Get socket number by its address
2225
; SOCKET_ptr_to_num: Get socket number by its address.            ;
-
 
2226
;                                                                 ;
-
 
2227
;  IN:  eax = socket ptr                                          ;
2117
;
2228
;                                                                 ;
2118
; IN:  eax = socket ptr
2229
; OUT:  eax = socket number                                       ;
2119
; OUT: eax = 0 on error, socket num otherwise
-
 
-
 
2230
;       eax = 0 on error                                          ;
2120
;       ZF = set on error
2231
;       ZF = set on error                                         ;
2121
;
2232
;                                                                 ;
2122
;---------------------------------------------------
2233
;-----------------------------------------------------------------;
Line 2123... Line 2234...
2123
align 4
2234
align 4
Line 2136... Line 2247...
2136
  .error:
2247
  .error:
2137
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_ptr_to_num: not found\n", eax
2248
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_ptr_to_num: not found\n", eax
2138
        ret
2249
        ret
Line 2139... Line 2250...
2139
 
2250
 
2140
 
-
 
2141
;---------------------------------------------------
2251
 
2142
;
-
 
2143
; SOCKET_check
2252
;-----------------------------------------------------------------;
2144
;
-
 
-
 
2253
;                                                                 ;
2145
; checks if the given value is really a socket ptr
2254
; SOCKET_check: Checks if the given ptr is really a socket ptr.   ;
-
 
2255
;                                                                 ;
2146
;
2256
;  IN:  eax = socket ptr                                          ;
2147
; IN:  eax = socket ptr
2257
;                                                                 ;
2148
; OUT: eax = 0 on error, unchanged otherwise
-
 
-
 
2258
; OUT:  eax = 0 on error                                          ;
2149
;       ZF = set on error
2259
;       ZF = set on error                                         ;
2150
;
2260
;                                                                 ;
2151
;---------------------------------------------------
2261
;-----------------------------------------------------------------;
Line 2152... Line 2262...
2152
align 4
2262
align 4
Line -... Line 2263...
-
 
2263
SOCKET_check:
-
 
2264
 
2153
SOCKET_check:
2265
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_check: %x\n", eax
2154
 
2266
 
Line 2155... Line 2267...
2155
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_check: %x\n", eax
2267
        test    eax, eax
2156
 
2268
        jz      .error
Line 2166... Line 2278...
2166
 
2278
 
2167
  .done:
2279
  .done:
2168
        mov     eax, ebx
2280
        mov     eax, ebx
2169
        test    eax, eax
2281
        test    eax, eax
-
 
2282
        pop     ebx
Line -... Line 2283...
-
 
2283
        ret
-
 
2284
 
-
 
2285
  .error:
2170
        pop     ebx
2286
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_check: called with argument 0\n"
Line 2171... Line 2287...
2171
 
2287
        DEBUGF  DEBUG_NETWORK_ERROR, "stack: 0x%x, 0x%x, 0x%x\n", [esp], [esp+4], [esp+8]
2172
        ret
-
 
2173
 
2288
        ret
2174
 
-
 
2175
 
2289
 
2176
;---------------------------------------------------
-
 
-
 
2290
 
2177
;
2291
 
-
 
2292
;-----------------------------------------------------------------;
2178
; SOCKET_check_owner
2293
;                                                                 ;
2179
;
-
 
-
 
2294
; SOCKET_check_owner: Check if the caller app owns the socket.    ;
2180
; checks if the caller application owns the socket
2295
;                                                                 ;
2181
;
2296
;  IN:  eax = socket ptr                                          ;
2182
; IN:  eax = socket ptr
2297
;                                                                 ;
Line 2183... Line 2298...
2183
; OUT:  ZF = true/false
2298
; OUT:  ZF = true/false                                           ;
Line 2197... Line 2312...
2197
        ret
2312
        ret
Line 2198... Line 2313...
2198
 
2313
 
2199
 
-
 
-
 
2314
 
2200
 
2315
 
2201
 
-
 
2202
;------------------------------------------------------
2316
 
2203
;
2317
;-----------------------------------------------------------------;
2204
; SOCKET_process_end
2318
;                                                                 ;
2205
;
-
 
-
 
2319
; SOCKET_process_end:                                             ;
2206
; Kernel calls this function when a certain process ends
2320
; Kernel calls this function when a certain process ends.         ;
-
 
2321
; This function will check if the process had any open sockets,   ;
2207
; This function will check if the process had any open sockets
2322
; and update them accordingly (clean up).                         ;
2208
; And update them accordingly (clean up)
-
 
-
 
2323
;                                                                 ;
2209
;
2324
;  IN:  edx = pid                                                 ;
2210
; IN:  edx = pid
2325
;                                                                 ;
2211
; OUT: /
2326
; OUT:  /                                                         ;
Line 2212... Line 2327...
2212
;
2327
;                                                                 ;
Line 2275... Line 2390...
2275
        ret
2390
        ret
Line 2276... Line 2391...
2276
 
2391
 
2277
 
-
 
-
 
2392
 
2278
 
2393
 
2279
 
-
 
-
 
2394
 
2280
;-----------------------------------------------------------------
2395
;-----------------------------------------------------------------;
-
 
2396
;                                                                 ;
2281
;
2397
; SOCKET_is_connecting: Update socket state.                      ;
2282
; SOCKET_is_connecting
-
 
-
 
2398
;                                                                 ;
2283
;
2399
;  IN:  eax = socket ptr                                          ;
2284
;  IN:  eax = socket ptr
-
 
2285
;  OUT: /
2400
;                                                                 ;
2286
;
2401
;  OUT: /                                                         ;
Line 2287... Line 2402...
2287
;-----------------------------------------------------------------
2402
;                                                                 ;
Line 2288... Line 2403...
2288
 
2403
;-----------------------------------------------------------------;
2289
align 4
2404
align 4
2290
SOCKET_is_connecting:
-
 
2291
 
2405
SOCKET_is_connecting:
Line 2292... Line 2406...
2292
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_is_connecting: %x\n", eax
2406
 
2293
 
-
 
-
 
2407
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_is_connecting: %x\n", eax
2294
        and     [eax + SOCKET.state], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING)
2408
 
2295
        or      [eax + SOCKET.state], SS_ISCONNECTING
-
 
-
 
2409
        and     [eax + SOCKET.state], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING)
2296
 
2410
        or      [eax + SOCKET.state], SS_ISCONNECTING
-
 
2411
        ret
2297
        ret
2412
 
2298
 
-
 
-
 
2413
 
2299
 
2414
 
2300
 
-
 
2301
;-----------------------------------------------------------------
2415
;-----------------------------------------------------------------;
2302
;
2416
;                                                                 ;
Line 2303... Line 2417...
2303
; SOCKET_is_connected
2417
; SOCKET_is_connected: Update socket state.                       ;
Line 2304... Line 2418...
2304
;
2418
;                                                                 ;
2305
;  IN:  eax = socket ptr
2419
;  IN:  eax = socket ptr                                          ;
2306
;  OUT: /
-
 
2307
;
2420
;                                                                 ;
Line 2308... Line 2421...
2308
;-----------------------------------------------------------------
2421
;  OUT: /                                                         ;
2309
 
-
 
-
 
2422
;                                                                 ;
2310
align 4
2423
;-----------------------------------------------------------------;
2311
SOCKET_is_connected:
-
 
-
 
2424
align 4
2312
 
2425
SOCKET_is_connected:
-
 
2426
 
2313
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_is_connected: %x\n", eax
2427
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_is_connected: %x\n", eax
2314
 
-
 
-
 
2428
 
2315
        and     [eax + SOCKET.state], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING)
2429
        and     [eax + SOCKET.state], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING)
2316
        or      [eax + SOCKET.state], SS_ISCONNECTED
-
 
2317
 
2430
        or      [eax + SOCKET.state], SS_ISCONNECTED
2318
        jmp     SOCKET_notify
2431
        jmp     SOCKET_notify
Line 2319... Line 2432...
2319
 
2432
 
Line 2320... Line 2433...
2320
 
2433
 
2321
 
2434
 
2322
 
-
 
2323
;-----------------------------------------------------------------
2435
 
Line 2324... Line 2436...
2324
;
2436
;-----------------------------------------------------------------;
2325
; SOCKET_is_disconnecting
-
 
-
 
2437
;                                                                 ;
2326
;
2438
; SOCKET_is_disconnecting: Update socket state.                   ;
2327
;  IN:  eax = socket ptr
-
 
-
 
2439
;                                                                 ;
2328
;  OUT: /
2440
;  IN:  eax = socket ptr                                          ;
-
 
2441
;                                                                 ;
2329
;
2442
;  OUT: /                                                         ;
2330
;-----------------------------------------------------------------
-
 
-
 
2443
;                                                                 ;
2331
 
2444
;-----------------------------------------------------------------;
2332
align 4
-
 
2333
SOCKET_is_disconnecting:
2445
align 4
2334
 
2446
SOCKET_is_disconnecting:
Line 2335... Line 2447...
2335
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnecting: %x\n", eax
2447
 
Line 2336... Line 2448...
2336
 
2448
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnecting: %x\n", eax
2337
        and     [eax + SOCKET.state], not (SS_ISCONNECTING)
2449
 
2338
        or      [eax + SOCKET.state], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE
-
 
2339
 
-
 
2340
        jmp     SOCKET_notify
2450
        and     [eax + SOCKET.state], not (SS_ISCONNECTING)
Line 2341... Line 2451...
2341
 
2451
        or      [eax + SOCKET.state], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE
2342
 
-
 
-
 
2452
        jmp     SOCKET_notify
2343
 
2453
 
2344
;-----------------------------------------------------------------
-
 
-
 
2454
 
2345
;
2455
 
-
 
2456
;-----------------------------------------------------------------;
2346
; SOCKET_is_disconnected
2457
;                                                                 ;
2347
;
-
 
-
 
2458
; SOCKET_is_disconnected: Update socket state.                    ;
2348
;  IN:  eax = socket ptr
2459
;                                                                 ;
2349
;  OUT: /
-
 
2350
;
2460
;  IN:  eax = socket ptr                                          ;
2351
;-----------------------------------------------------------------
2461
;                                                                 ;
Line 2352... Line 2462...
2352
 
2462
;  OUT: /                                                         ;
Line 2353... Line 2463...
2353
align 4
2463
;                                                                 ;
2354
SOCKET_is_disconnected:
-
 
2355
 
2464
;-----------------------------------------------------------------;
2356
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnected: %x\n", eax
-
 
2357
 
-
 
2358
        and     [eax + SOCKET.state], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING)
-
 
Line 2359... Line -...
2359
        or      [eax + SOCKET.state], SS_CANTRCVMORE + SS_CANTSENDMORE
-
 
2360
 
-
 
2361
 
-
 
2362
        jmp     SOCKET_notify
-
 
2363
 
-
 
2364
 
-
 
2365
 
-
 
2366
;-----------------------------------------------------------------
-
 
Line -... Line 2465...
-
 
2465
align 4
-
 
2466
SOCKET_is_disconnected:
-
 
2467
 
-
 
2468
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_is_disconnected: %x\n", eax
-
 
2469
 
-
 
2470
        and     [eax + SOCKET.state], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING)
-
 
2471
        or      [eax + SOCKET.state], SS_CANTRCVMORE + SS_CANTSENDMORE
-
 
2472
        jmp     SOCKET_notify
-
 
2473
 
2367
;
2474
 
2368
; SOCKET_cant_recv_more
2475
 
Line 2369... Line 2476...
2369
;
2476
;-----------------------------------------------------------------;
Line 2370... Line 2477...
2370
;  IN:  eax = socket ptr
2477
;                                                                 ;
2371
;  OUT: /
2478
; SOCKET_cant_recv_more: Update socket state.                     ;
2372
;
-
 
2373
;-----------------------------------------------------------------
2479
;                                                                 ;
2374
 
-
 
2375
align 4
-
 
Line 2376... Line 2480...
2376
SOCKET_cant_recv_more:
2480
;  IN:  eax = socket ptr                                          ;
2377
 
2481
;                                                                 ;
2378
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_cant_recv_more: %x\n", eax
2482
;  OUT: /                                                         ;
2379
 
2483
;                                                                 ;