Subversion Repositories Kolibri OS

Rev

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

Rev 3698 Rev 3704
Line 300... Line 300...
300
        mov     [esp+32], edi                   ; return socketnumber
300
        mov     [esp+32], edi                   ; return socketnumber
301
        DEBUGF  DEBUG_NETWORK_VERBOSE, "socknum=%u\n", edi
301
        DEBUGF  DEBUG_NETWORK_VERBOSE, "socknum=%u\n", edi
Line 302... Line 302...
302
 
302
 
303
;        push    edx
303
;        push    edx
304
;        and     edx, SO_NONBLOCK
304
;        and     edx, SO_NONBLOCK
305
        or      [eax + SOCKET.options], SO_NONBLOCK ;edx        ; HACK: make all sockets non-blocking untill API and applications are fixed
305
;        or      [eax + SOCKET.options], SO_NONBLOCK ;edx        ; HACK: make all sockets non-blocking untill API and applications are fixed
306
;        pop     edx
306
;        pop     edx
Line 307... Line 307...
307
;        and     edx, not SO_NONBLOCK
307
;        and     edx, not SO_NONBLOCK
308
 
308
 
Line 609... Line 609...
609
  .block:
609
  .block:
610
        test    [eax + SOCKET.options], SO_NONBLOCK
610
        test    [eax + SOCKET.options], SO_NONBLOCK
611
        jz      .loop
611
        jz      .loop
Line 612... Line 612...
612
 
612
 
613
        mov     dword[esp+20], EWOULDBLOCK
613
        mov     dword[esp+20], EWOULDBLOCK
614
        mov     dword[esp+32], 0                 ; Should be -1? or not?
614
        mov     dword[esp+32], -1
Line 615... Line 615...
615
        ret
615
        ret
616
 
616
 
617
  .loop:
617
  .loop:
Line 858... Line 858...
858
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi
858
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi
Line 859... Line 859...
859
 
859
 
860
        call    SOCKET_num_to_ptr
860
        call    SOCKET_num_to_ptr
Line -... Line 861...
-
 
861
        jz      .invalid
-
 
862
 
861
        jz      .invalid
863
  .loop:
-
 
864
        push    edi
-
 
865
        call    [eax + SOCKET.rcv_proc]
-
 
866
        pop     edi
-
 
867
 
-
 
868
        cmp     ebx, EWOULDBLOCK
-
 
869
        jne     .return
-
 
870
 
-
 
871
        test    edi, MSG_DONTWAIT
-
 
872
        jnz     .return_err
-
 
873
 
-
 
874
;        test    [eax + SOCKET.options], SO_NONBLOCK
-
 
875
;        jnz     .return_err
-
 
876
 
Line -... Line 877...
-
 
877
        call    SOCKET_block
-
 
878
        jmp     .loop
-
 
879
 
-
 
880
 
-
 
881
  .invalid:
-
 
882
        push    EINVAL
-
 
883
        pop     ebx
862
 
884
  .return_err:
863
        call    [eax + SOCKET.rcv_proc]
885
        mov     eax, -1
864
 
886
  .return:
Line 865... Line 887...
865
        mov     [esp+20], ebx
887
        mov     [esp+20], ebx
866
        mov     [esp+32], eax
-
 
867
        ret
-
 
868
 
888
        mov     [esp+32], eax
Line 869... Line 889...
869
 
889
        ret
870
  .invalid:
890
 
871
        mov     dword[esp+20], EINVAL
-
 
Line 872... Line -...
872
        mov     dword[esp+32], -1
-
 
873
        ret
891
 
Line 874... Line -...
874
 
-
 
875
align 4
892
 
Line -... Line 893...
-
 
893
 
876
SOCKET_receive_dgram:
894
 
877
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: DGRAM\n"
895
align 4
Line 878... Line 896...
878
 
896
SOCKET_receive_dgram:
879
        mov     ebx, esi
897
 
Line 880... Line 898...
880
        mov     edi, edx                                        ; addr to buffer
898
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: DGRAM\n"
881
 
899
 
882
  .loop:
900
        mov     ebx, esi                                        ; bufferlength
883
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, .block      ; destroys esi and ecx
901
 
Line 884... Line 902...
884
 
902
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, .wouldblock ; sets esi only on success.
-
 
903
        mov     ecx, [esi + socket_queue_entry.data_size]
885
        mov     ecx, [esi + socket_queue_entry.data_size]
904
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: %u bytes data\n", ecx
886
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: %u bytes data\n", ecx
905
 
887
 
906
        cmp     ecx, ebx                                        ; If data segment does not fit in applications buffer, abort
888
        cmp     ecx, ebx
907
        ja      .too_small
889
        ja      .too_small
908
 
Line 905... Line 924...
905
        test    ecx, ecx
924
        test    ecx, ecx
906
        jz      .nd
925
        jz      .nd
907
        rep     movsd
926
        rep     movsd
908
  .nd:
927
  .nd:
Line 909... Line 928...
909
 
928
 
-
 
929
        call    kernel_free                                     ; free kernel buffer
910
        call    kernel_free                                     ; remove the packet
930
        pop     eax                                             ; return number of bytes copied to application
911
        pop     eax
931
        xor     ebx, ebx
Line 912... Line 932...
912
        ret
932
        ret
913
 
933
 
914
  .too_small:
934
  .too_small:
-
 
935
        mov     eax, -1
915
        mov     eax, -1
936
        push    EMSGSIZE
Line 916... Line -...
916
        mov     ebx, EMSGSIZE
-
 
917
        ret
-
 
918
 
-
 
919
  .block:
-
 
920
        test    [eax + SOCKET.options], SO_NONBLOCK
-
 
921
        jnz     .wouldblock
-
 
922
 
-
 
923
        call    SOCKET_block
937
        pop     ebx
924
        jmp     .loop
938
        ret
925
 
939
 
926
  .wouldblock:
940
  .wouldblock:
Line -... Line 941...
-
 
941
        push    EWOULDBLOCK
927
        mov     eax, -1
942
        pop     ebx
928
        mov     ebx, EWOULDBLOCK
943
        ret
Line 929... Line 944...
929
        ret
944
 
930
 
945
 
Line 943... Line 958...
943
        mov     [eax + SOCKET.TID], ebx         ; currently TID = PID in kolibrios :(
958
        mov     [eax + SOCKET.TID], ebx                         ; currently TID = PID in kolibrios :(
944
      @@:
959
      @@:
Line 945... Line 960...
945
 
960
 
Line -... Line 961...
-
 
961
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_stream
-
 
962
 
946
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_stream
963
; ... continue to SOCKET_receive_stream
947
 
964
 
Line 948... Line 965...
948
align 4
965
align 4
Line -... Line 966...
-
 
966
SOCKET_receive_stream:
-
 
967
 
-
 
968
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: STREAM\n"
-
 
969
 
949
SOCKET_receive_stream:
970
        cmp     [eax + STREAM_SOCKET.rcv + RING_BUFFER.size], 0
-
 
971
        je      .wouldblock
950
 
972
 
951
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_receive: STREAM\n"
973
        test    edi, MSG_PEEK
952
 
974
        jnz     .peek
Line 953... Line -...
953
        mov     ebx, edi
-
 
954
        mov     ecx, esi
-
 
955
        mov     edi, edx
-
 
956
        xor     edx, edx
-
 
957
 
-
 
958
        test    ebx, MSG_DONTWAIT
-
 
959
        jnz     .dontwait
-
 
960
  .loop:
-
 
961
        cmp     [eax + STREAM_SOCKET.rcv + RING_BUFFER.size], 0
-
 
962
        je      .block
975
 
963
  .dontwait:
976
        mov     ecx, esi
964
        test    ebx, MSG_PEEK
977
        mov     edi, edx
Line 965... Line 978...
965
        jnz     .peek
978
        xor     edx, edx
966
 
-
 
967
        add     eax, STREAM_SOCKET.rcv
-
 
968
        call    SOCKET_ring_read
-
 
969
        call    SOCKET_ring_free
979
 
970
 
-
 
971
        mov     eax, ecx                ; return number of bytes copied
-
 
972
        ret
-
 
973
 
-
 
974
  .peek:
-
 
975
        mov     eax, [eax + STREAM_SOCKET.rcv + RING_BUFFER.size]
-
 
976
        ret
-
 
977
 
-
 
978
  .block:
-
 
979
        test    [eax + SOCKET.options], SO_NONBLOCK
-
 
980
        jnz     .wouldblock
-
 
981
 
-
 
982
        call    SOCKET_block
-
 
983
        jmp     .loop
-
 
984
 
-
 
985
  .return0:
-
 
986
        test    [eax + SOCKET.options], SS_CANTRCVMORE
-
 
987
        jz      .ok
-
 
988
 
-
 
989
        xor     eax, eax
980
        add     eax, STREAM_SOCKET.rcv
Line 990... Line 981...
990
        dec     eax
981
        call    SOCKET_ring_read                                ; copy data from kernel buffer to application buffer
991
        ret
982
        call    SOCKET_ring_free                                ; free read memory
992
 
983
 
993
  .ok:
984
        mov     eax, ecx                                        ; return number of bytes copied
Line -... Line 985...
-
 
985
        xor     ebx, ebx                                        ; errorcode = 0 (no error)
-
 
986
        ret
-
 
987
 
-
 
988
  .wouldblock:
Line 994... Line 989...
994
        xor     eax, eax
989
        push    EWOULDBLOCK
995
        ret
990
        pop     ebx
996
 
991
        ret
Line 1249... Line 1244...
1249
        jne     .invalid
1244
        jne     .invalid
Line 1250... Line 1245...
1250
 
1245
 
1251
        cmp     dword [edx+4], SO_BINDTODEVICE
1246
        cmp     dword [edx+4], SO_BINDTODEVICE
Line 1252... Line -...
1252
        je      .bind
-
 
1253
 
-
 
1254
        cmp     dword [edx+4], SO_BLOCK
-
 
1255
        je      .block
1247
        je      .bind
1256
 
1248
 
1257
  .invalid:
1249
  .invalid:
1258
        mov     dword[esp+32], -1
1250
        mov     dword[esp+32], -1
Line 1281... Line 1273...
1281
        mov     [eax + SOCKET.device], 0
1273
        mov     [eax + SOCKET.device], 0
Line 1282... Line 1274...
1282
 
1274
 
1283
        mov     dword[esp+32], 0        ; success!
1275
        mov     dword[esp+32], 0        ; success!
Line 1284... Line -...
1284
        ret
-
 
1285
 
-
 
1286
  .block:
-
 
1287
        cmp     dword[edx+8], 0
-
 
1288
        je      .unblock
-
 
1289
 
-
 
1290
        and     [eax + SOCKET.options], not SO_NONBLOCK
-
 
1291
 
-
 
1292
        mov     dword[esp+32], 0        ; success!
-
 
1293
        ret
-
 
1294
 
-
 
1295
  .unblock:
-
 
1296
        or      [eax + SOCKET.options], SO_NONBLOCK
-
 
1297
 
-
 
1298
        mov     dword[esp+32], 0        ; success!
-
 
1299
        ret
1276
        ret
1300
 
1277
 
1301
  .already:
1278
  .already:
1302
        mov     dword[esp+20], EALREADY
1279
        mov     dword[esp+20], EALREADY
Line 1884... Line 1861...
1884
        jz      .error
1861
        jz      .error
Line 1885... Line 1862...
1885
 
1862
 
1886
        test    [eax + SOCKET.state], SS_BLOCKED
1863
        test    [eax + SOCKET.state], SS_BLOCKED
Line 1887... Line 1864...
1887
        jnz     .unblock
1864
        jnz     .unblock
1888
 
1865
 
Line 1889... Line 1866...
1889
        test    [eax + SOCKET.options], SO_NONBLOCK
1866
;        test    [eax + SOCKET.options], SO_NONBLOCK
Line 1890... Line 1867...
1890
        jz      .error
1867
;        jz      .error
1891
 
1868