Subversion Repositories Kolibri OS

Rev

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

Rev 6011 Rev 6413
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: 6011 $
18
$Revision: 6413 $
Line 19... Line 19...
19
 
19
 
20
struct  SOCKET
20
struct  SOCKET
Line 185... Line 185...
185
        optlen                  dd ?
185
        optlen                  dd ?
186
        optval                  dd ?
186
        optval                  dd ?
Line 187... Line 187...
187
 
187
 
Line 188... Line 188...
188
ends
188
ends
Line 189... Line 189...
189
 
189
 
190
SOCKETBUFFSIZE          = 4096          ; in bytes
190
SOCKET_STRUCT_SIZE      = 4096          ; in bytes
191
 
191
 
Line 192... Line 192...
192
SOCKET_QUEUE_SIZE       = 10            ; maximum number of incoming packets queued for 1 socket
192
SOCKET_QUEUE_SIZE       = 10            ; maximum number of incoming packets queued for 1 socket
193
; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start
193
; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start
Line 194... Line 194...
194
SOCKET_QUEUE_LOCATION   = (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue)
194
SOCKET_QUEUE_LOCATION   = (SOCKET_STRUCT_SIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue)
Line 1366... Line 1366...
1366
        call    socket_num_to_ptr
1366
        call    socket_num_to_ptr
1367
        test    eax, eax
1367
        test    eax, eax
1368
        jz      .invalid
1368
        jz      .invalid
Line 1369... Line 1369...
1369
 
1369
 
1370
        mov     esi, eax
1370
        mov     esi, eax
1371
        mov     ecx, SOCKETBUFFSIZE/4
1371
        mov     ecx, SOCKET_STRUCT_SIZE/4
Line 1372... Line 1372...
1372
        rep movsd
1372
        rep movsd
1373
 
1373
 
Line 1589... Line 1589...
1589
 
1589
 
1590
        push    esi
1590
        push    esi
Line 1591... Line 1591...
1591
        mov     esi, eax
1591
        mov     esi, eax
1592
 
1592
 
1593
        push    edx
1593
        push    edx
1594
        stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SWR
1594
        stdcall create_ring_buffer, SOCKET_BUFFER_SIZE, PG_SWR
1595
        pop     edx
1595
        pop     edx
Line 1596... Line 1596...
1596
        test    eax, eax
1596
        test    eax, eax
Line 1605... Line 1605...
1605
 
1605
 
1606
        mov     [esi + RING_BUFFER.start_ptr], eax
1606
        mov     [esi + RING_BUFFER.start_ptr], eax
1607
        mov     [esi + RING_BUFFER.write_ptr], eax
1607
        mov     [esi + RING_BUFFER.write_ptr], eax
1608
        mov     [esi + RING_BUFFER.read_ptr], eax
1608
        mov     [esi + RING_BUFFER.read_ptr], eax
1609
        mov     [esi + RING_BUFFER.size], 0
1609
        mov     [esi + RING_BUFFER.size], 0
1610
        add     eax, SOCKET_MAXDATA
1610
        add     eax, SOCKET_BUFFER_SIZE
1611
        mov     [esi + RING_BUFFER.end_ptr], eax
1611
        mov     [esi + RING_BUFFER.end_ptr], eax
Line 1612... Line 1612...
1612
        mov     eax, esi
1612
        mov     eax, esi
1613
 
1613
 
Line 1640... Line 1640...
1640
        lea     ecx, [eax + RING_BUFFER.mutex]
1640
        lea     ecx, [eax + RING_BUFFER.mutex]
1641
        call    mutex_lock                                      ; TODO: check what registers this function actually destroys
1641
        call    mutex_lock                                      ; TODO: check what registers this function actually destroys
1642
        popa
1642
        popa
Line 1643... Line 1643...
1643
 
1643
 
1644
; calculate available size
1644
; calculate available size
1645
        mov     edi, SOCKET_MAXDATA
1645
        mov     edi, SOCKET_BUFFER_SIZE
1646
        sub     edi, [eax + RING_BUFFER.size]                   ; available buffer size in edi
1646
        sub     edi, [eax + RING_BUFFER.size]                   ; available buffer size in edi
1647
        cmp     ecx, edi
1647
        cmp     ecx, edi
1648
        jbe     .copy
1648
        jbe     .copy
1649
        mov     ecx, edi
1649
        mov     ecx, edi
Line 1654... Line 1654...
1654
; update write ptr
1654
; update write ptr
1655
        push    edi
1655
        push    edi
1656
        add     edi, ecx
1656
        add     edi, ecx
1657
        cmp     edi, [eax + RING_BUFFER.end_ptr]
1657
        cmp     edi, [eax + RING_BUFFER.end_ptr]
1658
        jb      @f
1658
        jb      @f
1659
        sub     edi, SOCKET_MAXDATA                             ; WRAP
1659
        sub     edi, SOCKET_BUFFER_SIZE                         ; WRAP
1660
  @@:
1660
  @@:
Line 1661... Line 1661...
1661
 
1661
 
1662
        mov     [eax + RING_BUFFER.write_ptr], edi
1662
        mov     [eax + RING_BUFFER.write_ptr], edi
Line 1788... Line 1788...
1788
        add     [eax + RING_BUFFER.read_ptr], ecx
1788
        add     [eax + RING_BUFFER.read_ptr], ecx
Line 1789... Line 1789...
1789
 
1789
 
1790
        mov     edx, [eax + RING_BUFFER.end_ptr]
1790
        mov     edx, [eax + RING_BUFFER.end_ptr]
1791
        cmp     [eax + RING_BUFFER.read_ptr], edx
1791
        cmp     [eax + RING_BUFFER.read_ptr], edx
1792
        jb      @f
1792
        jb      @f
1793
        sub     [eax + RING_BUFFER.read_ptr], SOCKET_MAXDATA
1793
        sub     [eax + RING_BUFFER.read_ptr], SOCKET_BUFFER_SIZE
Line 1794... Line 1794...
1794
       @@:
1794
       @@:
1795
 
1795
 
1796
        push    eax ecx
1796
        push    eax ecx
Line 1903... Line 1903...
1903
        jnz     .un_block
1903
        jnz     .un_block
Line 1904... Line 1904...
1904
 
1904
 
1905
; Socket and thread exists and socket is of non blocking type.
1905
; Socket and thread exists and socket is of non blocking type.
1906
; We'll try to flag an event to the thread.
1906
; We'll try to flag an event to the thread.
1907
        shl     ecx, 8
1907
        shl     ecx, 8
Line 1908... Line 1908...
1908
        or      [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
1908
        or      [SLOT_BASE + ecx + APPDATA.event_mask], EVENT_NETWORK
1909
 
1909
 
1910
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: poking thread %u!\n", eax
1910
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: poking thread %u!\n", ebx
Line 1911... Line 1911...
1911
        pop     esi ecx ebx
1911
        pop     esi ecx ebx
Line 1939... Line 1939...
1939
align 4
1939
align 4
1940
socket_alloc:
1940
socket_alloc:
Line 1941... Line 1941...
1941
 
1941
 
Line 1942... Line 1942...
1942
        push    ebx
1942
        push    ebx
1943
 
1943
 
1944
        stdcall kernel_alloc, SOCKETBUFFSIZE
1944
        stdcall kernel_alloc, SOCKET_STRUCT_SIZE
1945
        or      eax, eax
1945
        or      eax, eax
Line 1946... Line 1946...
1946
        jz      .nomem
1946
        jz      .nomem
1947
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_alloc: ptr=%x\n", eax
1947
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_alloc: ptr=%x\n", eax
1948
 
1948
 
1949
; zero-initialize allocated memory
1949
; zero-initialize allocated memory
1950
        push    eax
1950
        push    eax
1951
        mov     edi, eax
1951
        mov     edi, eax
1952
        mov     ecx, SOCKETBUFFSIZE / 4
1952
        mov     ecx, SOCKET_STRUCT_SIZE / 4
Line 1953... Line 1953...
1953
        xor     eax, eax
1953
        xor     eax, eax