Subversion Repositories Kolibri OS

Rev

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

Rev 4457 Rev 4587
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;  Part of the TCP/IP network stack for KolibriOS                 ;;
6
;;  Part of the TCP/IP network stack for KolibriOS                 ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;   Written by hidnplayr@kolibrios.org,                           ;;
8
;;   Written by hidnplayr@kolibrios.org,                           ;;
Line 291... Line 291...
291
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_open: domain=%u type=%u protocol=%x ", ecx, edx, esi
291
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_open: domain=%u type=%u protocol=%x ", ecx, edx, esi
Line 292... Line 292...
292
 
292
 
293
        push    ecx edx esi
293
        push    ecx edx esi
294
        call    SOCKET_alloc
294
        call    SOCKET_alloc
-
 
295
        pop     esi edx ecx
295
        pop     esi edx ecx
296
        test    eax, eax
Line 296... Line 297...
296
        jz      .nobuffs
297
        jz      .nobuffs
297
 
298
 
Line 695... Line 696...
695
 
696
 
Line 696... Line 697...
696
        or      [eax + SOCKET.options], SO_NONBLOCK             ; Mark the socket as non blocking, we dont want it to block any longer!
697
        or      [eax + SOCKET.options], SO_NONBLOCK             ; Mark the socket as non blocking, we dont want it to block any longer!
697
 
698
 
698
        test    [eax + SOCKET.state], SS_BLOCKED                ; Is the socket still in blocked state?
699
        test    [eax + SOCKET.state], SS_BLOCKED                ; Is the socket still in blocked state?
699
        jz      @f
700
        jz      @f
Line 700... Line 701...
700
        call    SOCKET_notify.unblock                           ; Unblock it.
701
        call    SOCKET_notify                                   ; Unblock it.
701
  @@:
702
  @@:
Line 1190... Line 1191...
1190
SOCKET_pair:
1191
SOCKET_pair:
Line 1191... Line 1192...
1191
 
1192
 
Line 1192... Line 1193...
1192
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_pair\n"
1193
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_pair\n"
-
 
1194
 
1193
 
1195
        call    SOCKET_alloc
1194
        call    SOCKET_alloc
1196
        test    eax, eax
Line 1195... Line 1197...
1195
        jz      .nomem1
1197
        jz      .nomem1
1196
        mov     [esp+32], edi   ; application's eax
1198
        mov     [esp+32], edi   ; application's eax
Line 1202... Line 1204...
1202
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_local
1204
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_local
1203
        mov     [eax + SOCKET.PID], 0
1205
        mov     [eax + SOCKET.PID], 0
1204
        mov     ebx, eax
1206
        mov     ebx, eax
Line 1205... Line 1207...
1205
 
1207
 
-
 
1208
        call    SOCKET_alloc
1206
        call    SOCKET_alloc
1209
        test    eax, eax
1207
        jz      .nomem2
1210
        jz      .nomem2
Line 1208... Line 1211...
1208
        mov     [esp+20], edi   ; application's ebx
1211
        mov     [esp+20], edi   ; application's ebx
1209
 
1212
 
Line 1705... Line 1708...
1705
align 4
1708
align 4
1706
SOCKET_block:
1709
SOCKET_block:
Line 1707... Line 1710...
1707
 
1710
 
Line 1708... Line -...
1708
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_block: %x\n", eax
-
 
1709
 
1711
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_block: %x\n", eax
-
 
1712
 
-
 
1713
        push    eax
1710
        pushf
1714
 
Line 1711... Line 1715...
1711
        push    eax
1715
        pushf
1712
        cli
1716
        cli
Line 1722... Line 1726...
1722
        ; Remember the thread ID so we can wake it up again
1726
        ; Remember the thread ID so we can wake it up again
1723
        mov     edx, [edx + TASKDATA.pid]
1727
        mov     edx, [edx + TASKDATA.pid]
1724
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_block: suspending thread: %u\n", edx
1728
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_block: suspending thread: %u\n", edx
1725
        mov     [eax + SOCKET.TID], edx
1729
        mov     [eax + SOCKET.TID], edx
1726
        pop     edx
1730
        pop     edx
-
 
1731
        popf
Line 1727... Line 1732...
1727
 
1732
 
1728
        call    change_task
1733
        call    change_task
1729
        pop     eax
-
 
Line 1730... Line 1734...
1730
        popf
1734
        pop     eax
Line 1731... Line 1735...
1731
 
1735
 
Line 1732... Line 1736...
1732
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_block: continueing\n"
1736
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_block: continuing\n"
Line 1750... Line 1754...
1750
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: %x\n", eax
1754
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: %x\n", eax
Line 1751... Line 1755...
1751
 
1755
 
1752
        call    SOCKET_check
1756
        call    SOCKET_check
Line 1753... Line -...
1753
        jz      .error
-
 
1754
 
-
 
1755
        test    [eax + SOCKET.state], SS_BLOCKED
-
 
1756
        jnz     .unblock
-
 
1757
 
-
 
1758
;        test    [eax + SOCKET.options], SO_NONBLOCK
-
 
1759
;        jz      .error
-
 
1760
 
-
 
1761
        push    eax ecx esi
-
 
1762
 
-
 
1763
; socket exists and is of non blocking type.
-
 
1764
; We'll try to flag an event to the thread
-
 
1765
 
-
 
1766
        mov     eax, [eax + SOCKET.TID]
-
 
1767
        test    eax, eax
-
 
1768
        jz      .done
1757
        jz      .error
1769
        mov     ecx, 1
-
 
1770
        mov     esi, TASK_DATA + TASKDATA.pid
-
 
1771
 
-
 
1772
  .next_pid:
-
 
1773
        cmp     [esi], eax
-
 
1774
        je      .found_pid
-
 
1775
        inc     ecx
-
 
1776
        add     esi, 0x20
-
 
1777
        cmp     ecx, [TASK_COUNT]
-
 
1778
        jbe     .next_pid
-
 
1779
; PID not found, TODO: close socket!
-
 
1780
        jmp     .done
-
 
1781
 
-
 
1782
  .found_pid:
-
 
1783
        shl     ecx, 8
-
 
1784
        or      [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
-
 
1785
 
-
 
1786
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: poking thread %u!\n", eax
-
 
1787
        jmp     .done
-
 
1788
 
1758
 
1789
  .unblock:
-
 
1790
        push    eax ecx esi
-
 
1791
        ; Clear the 'socket is blocked' flag
-
 
1792
        and     [eax + SOCKET.state], not SS_BLOCKED
-
 
1793
 
1759
; Find the associated thread's TASK_DATA
1794
        ; Find the thread's TASK_DATA
1760
        push    ebx ecx esi
1795
        mov     eax, [eax + SOCKET.TID]
1761
        mov     ebx, [eax + SOCKET.TID]
1796
        test    eax, eax
1762
        test    ebx, ebx
1797
        jz      .error
1763
        jz      .error2
1798
        xor     ecx, ecx
1764
        xor     ecx, ecx
1799
        inc     ecx
1765
        inc     ecx
1800
        mov     esi, TASK_DATA
1766
        mov     esi, TASK_DATA
1801
  .next:
1767
  .next:
1802
        cmp     [esi + TASKDATA.pid], eax
1768
        cmp     [esi + TASKDATA.pid], ebx
1803
        je      .found
1769
        je      .found
1804
        inc     ecx
1770
        inc     ecx
1805
        add     esi, 0x20
1771
        add     esi, 0x20
-
 
1772
        cmp     ecx, [TASK_COUNT]
-
 
1773
        jbe     .next
-
 
1774
 
-
 
1775
  .error2:
1806
        cmp     ecx, [TASK_COUNT]
1776
; PID not found, TODO: close socket!
-
 
1777
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_notify: error finding thread 0x%x !\n", ebx
-
 
1778
        pop     esi ecx ebx
-
 
1779
        ret
-
 
1780
 
-
 
1781
  .error:
-
 
1782
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_notify: invalid socket ptr: 0x%x !\n", eax
1807
        jbe     .next
1783
        ret
-
 
1784
 
-
 
1785
  .found:
Line -... Line 1786...
-
 
1786
        test    [eax + SOCKET.state], SS_BLOCKED
1808
        jmp     .error
1787
        jnz     .un_block
1809
  .found:
1788
 
1810
 
1789
; socket and thread exists and socket is of non blocking type.
Line 1811... Line -...
1811
        ; Run the thread
-
 
-
 
1790
; We'll try to flag an event to the thread.
1812
        mov     [esi + TASKDATA.state], 0       ; Running
1791
        shl     ecx, 8
-
 
1792
        or      [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
Line -... Line 1793...
-
 
1793
 
1813
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: Unblocked socket!\n"
1794
        DEBUGF  DEBUG_NETWORK_VERBOSE, "SOCKET_notify: poking thread %u!\n", eax
-
 
1795
        pop     esi ecx ebx
-
 
1796
        ret
-
 
1797
 
-
 
1798
 
-
 
1799
  .un_block:
-
 
1800
; socket and thread exists and socket is of blocking type
-
 
1801
; We'll try to unblock it.
1814
 
1802
        and     [eax + SOCKET.state], not SS_BLOCKED    ; Clear the 'socket is blocked' flag
Line 1815... Line 1803...
1815
  .done:
1803
        mov     [esi + TASKDATA.state], 0               ; Run the thread
1816
        pop     esi ecx eax
1804
 
Line 1828... Line 1816...
1828
; put into beginning of list (which is a fastest way).
1816
; put into beginning of list (which is a fastest way).
1829
;
1817
;
1830
; IN:  /
1818
; IN:  /
1831
; OUT: eax = 0 on error, socket ptr otherwise
1819
; OUT: eax = 0 on error, socket ptr otherwise
1832
;      edi = socket number
1820
;      edi = socket number
1833
;       ZF = cleared on error
-
 
1834
;
1821
;
1835
;--------------------------------------------------------------------
1822
;--------------------------------------------------------------------
1836
align 4
1823
align 4
1837
SOCKET_alloc:
1824
SOCKET_alloc:
Line 1915... Line 1902...
1915
        call    mutex_unlock
1902
        call    mutex_unlock
1916
        popa
1903
        popa
1917
       @@:
1904
       @@:
Line 1918... Line 1905...
1918
 
1905
 
1919
        mov     [net_sockets + SOCKET.NextPtr], eax
-
 
Line 1920... Line 1906...
1920
        or      eax, eax                ; used to clear zero flag
1906
        mov     [net_sockets + SOCKET.NextPtr], eax
1921
 
1907
 
1922
        pusha
1908
        pusha
1923
        mov     ecx, socket_mutex
1909
        mov     ecx, socket_mutex
Line 2020... Line 2006...
2020
 
2006
 
2021
; Allocate new socket
2007
; Allocate new socket
2022
        push    ebx
2008
        push    ebx
2023
        call    SOCKET_alloc
2009
        call    SOCKET_alloc
-
 
2010
        pop     ebx
2024
        pop     ebx
2011
        test    eax, eax
Line 2025... Line 2012...
2025
        jz      .fail
2012
        jz      .fail
2026
 
2013
 
2027
        push    eax
2014
        push    eax
Line 2099... Line 2086...
2099
        pusha
2086
        pusha
2100
        mov     ecx, socket_mutex
2087
        mov     ecx, socket_mutex
2101
        call    mutex_unlock
2088
        call    mutex_unlock
2102
        popa
2089
        popa
Line 2103... Line 2090...
2103
 
2090
 
-
 
2091
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: socket %u not found!\n", eax
2104
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: not found\n", eax
2092
        DEBUGF  DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: caller = 0x%x\n", [esp]
Line 2105... Line 2093...
2105
        ret
2093
        ret
2106
 
2094