Subversion Repositories Kolibri OS

Rev

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

Rev 2993 Rev 2994
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: 2993 $
18
$Revision: 2994 $
Line 19... Line 19...
19
 
19
 
Line 226... Line 226...
226
}
226
}
Line 227... Line 227...
227
 
227
 
228
 
228
 
-
 
229
;-----------------------------------------------------------------
-
 
230
;
-
 
231
; SOCKET_block
-
 
232
;
-
 
233
;-----------------------------------------------------------------
-
 
234
macro   SOCKET_block socket, loop, done {
-
 
235
 
-
 
236
        test    [socket + SOCKET.options], SO_BLOCK     ; Is this a blocking socket?
-
 
237
        jz      done                                    ; No, return immediately
-
 
238
 
-
 
239
        push    esi
-
 
240
        mov     esi, 5                                  ; yes, wait for event
-
 
241
        call    delay_ms
-
 
242
        pop     esi
-
 
243
 
-
 
244
        jmp     loop
-
 
245
 
-
 
246
}
-
 
247
 
-
 
248
 
229
;-----------------------------------------------------------------
249
;-----------------------------------------------------------------
230
;
250
;
231
; Socket API (function 74)
251
; Socket API (function 74)
232
;
252
;
233
;-----------------------------------------------------------------
253
;-----------------------------------------------------------------
Line 562... Line 582...
562
        popa
582
        popa
Line 563... Line 583...
563
 
583
 
564
        mov     eax, ebx
584
        mov     eax, ebx
Line -... Line 585...
-
 
585
        call    TCP_output
-
 
586
 
565
        call    TCP_output
587
;;; TODO: wait for successfull connection if blocking socket
566
 
588
 
Line 567... Line 589...
567
        mov     dword [esp+32], 0
589
        mov     dword [esp+32], 0
568
        ret
590
        ret
Line 664... Line 686...
664
        jne     s_error
686
        jne     s_error
Line 665... Line 687...
665
 
687
 
666
        cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
688
        cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
Line -... Line 689...
-
 
689
        jne     s_error
667
        jne     s_error
690
 
-
 
691
  .loop:
-
 
692
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .block
668
 
693
 
Line 669... Line 694...
669
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, s_error
694
; Ok, we got a socket ptr
670
        mov     eax, [esi]
695
        mov     eax, [esi]
671
 
696
 
672
; Change PID to that of the current process
697
; Change PID to that of the current process
Line -... Line 698...
-
 
698
        mov     ebx, [TASK_BASE]
673
        mov     ebx, [TASK_BASE]
699
        mov     ebx, [ebx + TASKDATA.pid]
674
        mov     ebx, [ebx + TASKDATA.pid]
700
        mov     [eax + SOCKET.PID], ebx
-
 
701
 
675
        mov     [eax + SOCKET.PID], ebx
702
; Convert it to a socket number
676
 
703
        call    SOCKET_ptr_to_num
Line -... Line 704...
-
 
704
        jz      s_error
-
 
705
; and return it to caller
Line 677... Line 706...
677
        call    SOCKET_ptr_to_num
706
        mov     [esp+32], eax
678
        jz      s_error
707
        ret
679
        mov     [esp+32], eax
708
 
680
        ret
709
  .block:
Line 717... Line 746...
717
        cmp     [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED    ; state must be LISTEN, SYN_SENT or CLOSED
746
        cmp     [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED    ; state must be LISTEN, SYN_SENT or CLOSED
718
        jb      .free
747
        jb      .free
Line 719... Line 748...
719
 
748
 
720
        call    TCP_usrclosed
749
        call    TCP_usrclosed
-
 
750
        call    TCP_output      ;;;; Fixme: is this nescessary??
-
 
751
 
721
        call    TCP_output      ;;;; Fixme: is this nescessary??
752
;;; TODO: wait for successfull termination if blocking socket
Line 722... Line 753...
722
        mov     dword [esp+32], 0
753
        mov     dword [esp+32], 0
Line 723... Line 754...
723
 
754
 
Line 758... Line 789...
758
        DEBUGF  1,"SOCKET_receive: DGRAM\n"
789
        DEBUGF  1,"SOCKET_receive: DGRAM\n"
Line 759... Line 790...
759
 
790
 
760
        mov     ebx, esi
791
        mov     ebx, esi
Line -... Line 792...
-
 
792
        mov     edi, edx                                        ; addr to buffer
761
        mov     edi, edx                                        ; addr to buffer
793
 
Line 762... Line 794...
762
 
794
  .loop:
763
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, s_error       ; destroys esi and ecx
795
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, .block      ; destroys esi and ecx
Line 764... Line 796...
764
 
796
 
Line 793... Line 825...
793
  .too_small:
825
  .too_small:
Line 794... Line 826...
794
 
826
 
795
        DEBUGF  1,"SOCKET_receive: Buffer too small\n"
827
        DEBUGF  1,"SOCKET_receive: Buffer too small\n"
Line -... Line 828...
-
 
828
        jmp     s_error
-
 
829
 
-
 
830
  .block:
-
 
831
        SOCKET_block    eax, .loop, s_error
796
        jmp     s_error
832
 
797
 
833
 
Line 798... Line 834...
798
align 4
834
align 4
Line 799... Line 835...
799
SOCKET_receive_tcp:
835
SOCKET_receive_tcp:
800
 
836
 
801
        DEBUGF  1,"SOCKET_receive: TCP\n"
-
 
802
 
837
        DEBUGF  1,"SOCKET_receive: TCP\n"
-
 
838
 
-
 
839
        mov     ecx, esi
803
        mov     ecx, esi
840
        mov     edi, edx
-
 
841
        xor     edx, edx
-
 
842
        add     eax, STREAM_SOCKET.rcv
804
        mov     edi, edx
843
  .loop:                            ;;;; FIXME: ecx!
Line 805... Line 844...
805
        add     eax, STREAM_SOCKET.rcv
844
        call    SOCKET_ring_read
806
        xor     edx, edx
-
 
807
        call    SOCKET_ring_read
845
        test    ecx, ecx
Line -... Line 846...
-
 
846
        jz      .block
-
 
847
        call    SOCKET_ring_free
-
 
848
 
Line 808... Line 849...
808
        call    SOCKET_ring_free
849
        mov     [esp+32], ecx                                   ; return number of bytes copied
809
 
850
        ret
810
        mov     [esp+32], ecx                                   ; return number of bytes copied
851
 
811
 
852
  .block:
Line 1306... Line 1347...
1306
; SOCKET_ring_read
1347
; SOCKET_ring_read
1307
;
1348
;
1308
;  IN:  eax = ring struct ptr
1349
;  IN:  eax = ring struct ptr
1309
;       ecx = bytes to read
1350
;       ecx = bytes to read
1310
;       edx = offset
1351
;       edx = offset
1311
;       edi = ptr to buffer
1352
;       edi = ptr to buffer start
1312
;
1353
;
-
 
1354
;  OUT: eax = unchanged
1313
;  OUT: ecx = number of bytes read (0 on error)
1355
;       ecx = number of bytes read (0 on error)
-
 
1356
;       edx = destroyed
-
 
1357
;       esi = destroyed
-
 
1358
;       edi = ptr to buffer end
1314
;
1359
;
1315
;-----------------------------------------------------------------
1360
;-----------------------------------------------------------------
1316
align 4
1361
align 4
1317
SOCKET_ring_read:
1362
SOCKET_ring_read: