Subversion Repositories Kolibri OS

Rev

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

Rev 3253 Rev 3257
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: 3253 $
18
$Revision: 3257 $
Line 19... Line 19...
19
 
19
 
Line 225... Line 225...
225
        xchg    al, ah
225
        xchg    al, ah
226
        mov     [last_TCP_port], ax
226
        mov     [last_TCP_port], ax
Line 227... Line 227...
227
 
227
 
Line 228... Line -...
228
}
-
 
229
 
-
 
230
 
-
 
231
;-----------------------------------------------------------------
-
 
232
;
-
 
233
; SOCKET_block
-
 
234
;
-
 
235
;-----------------------------------------------------------------
-
 
236
macro   SOCKET_block socket, loop, done {
-
 
237
 
-
 
238
        test    [socket + SOCKET.options], SO_BLOCK     ; Is this a blocking socket?
-
 
239
        jz      done                                    ; No, return immediately
-
 
240
 
-
 
241
        pusha
-
 
242
        mov     eax, EVENT_NETWORK
-
 
243
        mov     ebx, 1337                   ; UID: ????
-
 
244
        call    wait_event
-
 
245
        popa
-
 
246
 
-
 
247
        jmp     loop
-
 
248
 
-
 
249
}
-
 
250
 
228
}
251
 
229
 
252
;-----------------------------------------------------------------
230
;-----------------------------------------------------------------
253
;
231
;
254
; Socket API (function 74)
232
; Socket API (function 74)
Line 305... Line 283...
305
        jz      s_error
283
        jz      s_error
Line 306... Line 284...
306
 
284
 
307
        mov     [esp+32], edi                   ; return socketnumber
285
        mov     [esp+32], edi                   ; return socketnumber
Line -... Line 286...
-
 
286
        DEBUGF  2,"socknum=%u\n", edi
-
 
287
 
-
 
288
;        push    edx
-
 
289
;        and     edx, SO_NONBLOCK
-
 
290
        or      [eax + SOCKET.options], SO_NONBLOCK ;edx
-
 
291
;        pop     edx
308
        DEBUGF  2,"socknum=%u\n", edi
292
;        and     edx, not SO_NONBLOCK
309
 
293
 
310
        mov     [eax + SOCKET.Domain], ecx
294
        mov     [eax + SOCKET.Domain], ecx
Line 311... Line 295...
311
        mov     [eax + SOCKET.Type], edx
295
        mov     [eax + SOCKET.Type], edx
Line 709... Line 693...
709
; and return it to caller
693
; and return it to caller
710
        mov     [esp+32], eax
694
        mov     [esp+32], eax
711
        ret
695
        ret
Line 712... Line 696...
712
 
696
 
-
 
697
  .block:
713
  .block:
698
        test    [eax + SOCKET.options], SO_NONBLOCK
-
 
699
        jnz     s_error
-
 
700
 
-
 
701
        call    SOCKET_block
Line 714... Line 702...
714
        SOCKET_block    eax, .loop, s_error
702
        jmp     .loop
715
 
703
 
716
;-----------------------------------------------------------------
704
;-----------------------------------------------------------------
717
;
705
;
Line 830... Line 818...
830
 
818
 
831
        DEBUGF  2,"SOCKET_receive: Buffer too small\n"
819
        DEBUGF  2,"SOCKET_receive: Buffer too small\n"
Line 832... Line 820...
832
        jmp     s_error
820
        jmp     s_error
833
 
-
 
834
  .block:
-
 
835
        SOCKET_block    eax, .loop, s_error
-
 
836
 
-
 
837
align 4
-
 
838
SOCKET_receive_local:
-
 
839
 
821
 
840
        ; does this socket have a PID yet?
822
  .block:
Line 841... Line -...
841
        cmp     [eax + SOCKET.PID], 0
-
 
842
        jne     @f
823
        test    [eax + SOCKET.options], SO_NONBLOCK
843
 
-
 
844
        ; Change PID to that of current process
824
        jnz     s_error
845
        mov     ebx, [TASK_BASE]
-
 
Line 846... Line -...
846
        mov     ebx, [ebx + TASKDATA.pid]
-
 
Line 847... Line 825...
847
        mov     [eax + SOCKET.PID], ebx
825
 
848
      @@:
826
        call    SOCKET_block
Line 849... Line 827...
849
 
827
        jmp     .loop
Line 850... Line 828...
850
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_stream
828
 
851
 
829
 
852
align 4
830
align 4
853
SOCKET_receive_stream:
-
 
854
 
831
SOCKET_receive_stream:
855
        DEBUGF  1,"SOCKET_receive: STREAM\n"
832
 
856
 
833
        DEBUGF  1,"SOCKET_receive: STREAM\n"
-
 
834
 
857
        mov     ecx, esi
835
        mov     ecx, esi
858
        mov     edi, edx
836
        mov     edi, edx
Line 859... Line 837...
859
        xor     edx, edx
837
        xor     edx, edx
860
        add     eax, STREAM_SOCKET.rcv
838
  .loop:
Line 861... Line 839...
861
  .loop:
839
        cmp     [eax + STREAM_SOCKET.rcv + RING_BUFFER.size], 0
862
        cmp     [eax + RING_BUFFER.size], 0
840
        je      .block
-
 
841
        add     eax, STREAM_SOCKET.rcv
-
 
842
        call    SOCKET_ring_read
-
 
843
        call    SOCKET_ring_free
-
 
844
 
Line 863... Line 845...
863
        je      .block
845
        mov     [esp+32], ecx                                   ; return number of bytes copied
864
        call    SOCKET_ring_read
846
        ret
865
        call    SOCKET_ring_free
847
 
Line 965... Line 947...
965
 
947
 
966
 
948
 
Line -... Line 949...
-
 
949
align 4
-
 
950
SOCKET_send_local:
967
align 4
951
 
968
SOCKET_send_local:
952
        DEBUGF  1,"SOCKET_send: LOCAL\n"
969
 
953
 
Line 970... Line 954...
970
        ; does this socket have a PID yet?
954
        ; does this socket have a PID yet?
971
        cmp     [eax + SOCKET.PID], 0
955
        cmp     [eax + SOCKET.PID], 0
972
        jne     @f
956
        jne     @f
973
 
957
 
974
        ; Change PID to that of current process
958
        ; Change PID to that of current process
975
        mov     ebx, [TASK_BASE]
-
 
976
        mov     ebx, [ebx + TASKDATA.pid]
-
 
977
        mov     [eax + SOCKET.PID], ebx
-
 
978
      @@:
-
 
979
        mov     [eax + SOCKET.snd_proc], SOCKET_send_local_
-
 
980
 
-
 
Line 981... Line 959...
981
align 4
959
        mov     ebx, [TASK_BASE]
982
SOCKET_send_local_:
960
        mov     ebx, [ebx + TASKDATA.pid]
983
 
961
        mov     [eax + SOCKET.PID], ebx
984
        DEBUGF  1,"SOCKET_send: LOCAL\n"
962
      @@:
Line 996... Line 974...
996
 
974
 
997
        ; return the number of written bytes (or errorcode) to application
975
        ; return the number of written bytes (or errorcode) to application
Line 998... Line 976...
998
        mov     [esp+32], ecx
976
        mov     [esp+32], ecx
999
 
977
 
Line 1000... Line 978...
1000
        ; and notify the other end
978
        ; and notify the other end
Line 1001... Line 979...
1001
        call    SOCKET_notify_owner
979
        call    SOCKET_notify
Line 1112... Line 1090...
1112
 
1090
 
1113
  .block:
1091
  .block:
1114
        cmp     dword [edx+8], 0
1092
        cmp     dword [edx+8], 0
Line 1115... Line 1093...
1115
        je      .unblock
1093
        je      .unblock
Line 1116... Line 1094...
1116
 
1094
 
1117
        or      [eax + SOCKET.options], SO_BLOCK
1095
        and     [eax + SOCKET.options], not SO_NONBLOCK
Line 1118... Line 1096...
1118
 
1096
 
1119
        mov     dword [esp+32], 0       ; success!
1097
        mov     dword [esp+32], 0       ; success!
Line 1120... Line 1098...
1120
        ret
1098
        ret
1121
 
1099
 
Line 1149... Line 1127...
1149
 
1127
 
1150
        mov     [eax + SOCKET.Domain], AF_LOCAL
1128
        mov     [eax + SOCKET.Domain], AF_LOCAL
1151
        mov     [eax + SOCKET.Type], SOCK_STREAM
1129
        mov     [eax + SOCKET.Type], SOCK_STREAM
1152
        mov     [eax + SOCKET.Protocol], 0              ;;; CHECKME
1130
        mov     [eax + SOCKET.Protocol], 0              ;;; CHECKME
1153
        mov     [eax + SOCKET.snd_proc], SOCKET_send_local
1131
        mov     [eax + SOCKET.snd_proc], SOCKET_send_local
1154
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_local
1132
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_stream
Line 1155... Line 1133...
1155
        mov     ebx, eax
1133
        mov     ebx, eax
1156
 
1134
 
1157
        call    SOCKET_alloc
1135
        call    SOCKET_alloc
Line 1158... Line 1136...
1158
        jz      .error
1136
        jz      .error
1159
        mov     [esp+24], edi   ; application's ebx
1137
        mov     [esp+24], edi   ; application's ebx
1160
 
1138
 
1161
        mov     [eax + SOCKET.Domain], AF_LOCAL
1139
        mov     [eax + SOCKET.Domain], AF_LOCAL
1162
        mov     [eax + SOCKET.Type], SOCK_STREAM
1140
        mov     [eax + SOCKET.Type], SOCK_STREAM
Line 1163... Line 1141...
1163
        mov     [eax + SOCKET.Protocol], 0              ;;; CHECKME
1141
        mov     [eax + SOCKET.Protocol], 0              ;;; CHECKME
1164
        mov     [eax + SOCKET.snd_proc], SOCKET_send_local
1142
        mov     [eax + SOCKET.snd_proc], SOCKET_send_local
1165
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_local
1143
        mov     [eax + SOCKET.rcv_proc], SOCKET_receive_stream
Line 1373... Line 1351...
1373
        pusha
1351
        pusha
1374
        lea     ecx, [eax + SOCKET.mutex]
1352
        lea     ecx, [eax + SOCKET.mutex]
1375
        call    mutex_unlock
1353
        call    mutex_unlock
1376
        popa
1354
        popa
Line 1377... Line 1355...
1377
 
1355
 
Line 1378... Line 1356...
1378
        jmp     SOCKET_notify_owner
1356
        jmp     SOCKET_notify
1379
 
1357
 
Line 1380... Line 1358...
1380
  .full:
1358
  .full:
Line 1585... Line 1563...
1585
        ret
1563
        ret
Line 1586... Line 1564...
1586
 
1564
 
1587
 
1565
 
-
 
1566
;-----------------------------------------------------------------
-
 
1567
;
-
 
1568
; SOCKET_block
-
 
1569
;
-
 
1570
; Suspends the thread attached to a socket
-
 
1571
;
-
 
1572
;  IN:  eax = socket ptr
-
 
1573
;  OUT: /
-
 
1574
;
-
 
1575
;-----------------------------------------------------------------
-
 
1576
align 4
-
 
1577
SOCKET_block:
-
 
1578
 
-
 
1579
        DEBUGF  1,"SOCKET_block: %x\n", eax
-
 
1580
 
-
 
1581
        pushf
-
 
1582
        cli
-
 
1583
 
-
 
1584
        ; Set the 'socket is blocked' flag
-
 
1585
        or      [eax + SOCKET.state], SS_BLOCKED
-
 
1586
 
-
 
1587
        ; Suspend the thread
-
 
1588
        push    edx
-
 
1589
        mov     edx, [TASK_BASE]
-
 
1590
        DEBUGF  1,"SOCKET_block: suspending PID: %u\n", [edx + TASKDATA.pid]
-
 
1591
        mov     [edx + TASKDATA.state], 1               ; Suspended
-
 
1592
        pop     edx
-
 
1593
 
-
 
1594
        call    change_task
-
 
1595
        popf
-
 
1596
 
-
 
1597
        DEBUGF  1,"SOCKET_block: continueing\n"
-
 
1598
 
-
 
1599
        ret
-
 
1600
 
-
 
1601
 
1588
;-----------------------------------------------------------------
1602
;-----------------------------------------------------------------
1589
;
1603
;
1590
; SOCKET_notify_owner
1604
; SOCKET_notify
1591
;
1605
;
1592
; notify's the owner of a socket that something happened
1606
; notify's the owner of a socket that something happened
1593
;
1607
;
1594
;  IN:  eax = socket ptr
1608
;  IN:  eax = socket ptr
1595
;  OUT: /
1609
;  OUT: /
1596
;
1610
;
1597
;-----------------------------------------------------------------
1611
;-----------------------------------------------------------------
Line 1598... Line 1612...
1598
align 4
1612
align 4
Line 1599... Line 1613...
1599
SOCKET_notify_owner:
1613
SOCKET_notify:
1600
 
1614
 
Line -... Line 1615...
-
 
1615
        DEBUGF  1,"SOCKET_notify: %x\n", eax
-
 
1616
 
-
 
1617
        call    SOCKET_check
-
 
1618
        jz      .error
-
 
1619
 
-
 
1620
        test    [eax + SOCKET.state], SS_BLOCKED
1601
        DEBUGF  1,"SOCKET_notify_owner: %x\n", eax
1621
        jnz     .unblock
Line -... Line 1622...
-
 
1622
 
1602
 
1623
        test    [eax + SOCKET.options], SO_NONBLOCK
Line 1603... Line 1624...
1603
        call    SOCKET_check
1624
        jz      .error
1604
        jz      .error
1625
 
1605
 
1626
        push    eax ecx esi
1606
        push    eax ecx esi
1627
 
1607
 
1628
; socket exists and is of non blocking type.
Line 1608... Line 1629...
1608
; socket exists, now try to flag an event to the application
1629
; We'll try to flag an event to the thread
1609
 
1630
 
1610
        mov     eax, [eax + SOCKET.PID]
1631
        mov     eax, [eax + SOCKET.PID]
1611
        test    eax, eax
1632
        test    eax, eax
1612
        jz      .error2
1633
        jz      .done
1613
        mov     ecx, 1
1634
        mov     ecx, 1
1614
        mov     esi, TASK_DATA + TASKDATA.pid
1635
        mov     esi, TASK_DATA + TASKDATA.pid
1615
 
-
 
1616
       .next_pid:
1636
 
1617
        cmp     [esi], eax
-
 
1618
        je      .found_pid
1637
  .next_pid:
Line 1619... Line 1638...
1619
        inc     ecx
1638
        cmp     [esi], eax
1620
        add     esi, 0x20
1639
        je      .found_pid
1621
        cmp     ecx, [TASK_COUNT]
1640
        inc     ecx
1622
        jbe     .next_pid
1641
        add     esi, 0x20
-
 
1642
        cmp     ecx, [TASK_COUNT]
-
 
1643
        jbe     .next_pid
Line 1623... Line 1644...
1623
 
1644
; PID not found, TODO: close socket!
Line -... Line 1645...
-
 
1645
        jmp     .done
-
 
1646
 
-
 
1647
  .found_pid:
-
 
1648
        shl     ecx, 8
-
 
1649
        or      [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
-
 
1650
        mov     [check_idle_semaphore], 200                             ; What does this mean??
-
 
1651
 
-
 
1652
        DEBUGF  1,"SOCKET_notify: Raised a network event!\n"
-
 
1653
 
-
 
1654
        jmp     .done
-
 
1655
 
-
 
1656
  .unblock:
-
 
1657
        push    eax ecx esi
-
 
1658
        ; Clear the 'socket is blocked' flag
-
 
1659
        and     [eax + SOCKET.state], not SS_BLOCKED
-
 
1660
 
-
 
1661
        ; Find the thread's TASK_DATA
-
 
1662
        mov     eax, [eax + SOCKET.PID]
-
 
1663
        test    eax, eax
-
 
1664
        jz      .error
-
 
1665
        xor     ecx, ecx
-
 
1666
        inc     ecx
-
 
1667
        mov     esi, TASK_DATA
-
 
1668
  .next:
-
 
1669
        cmp     [esi + TASKDATA.pid], eax
-
 
1670
        je      .found
1624
; PID not found, TODO: close socket!
1671
        inc     ecx
1625
 
1672
        add     esi, 0x20
Line 1626... Line 1673...
1626
        jmp     .error2
1673
        cmp     ecx, [TASK_COUNT]
1627
 
-
 
1628
       .found_pid:
1674
        jbe     .next
Line 1629... Line 1675...
1629
        shl     ecx, 8
1675
        jmp     .error
1630
        or      [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
1676
  .found:
Line 1964... Line 2010...
1964
 
2010
 
Line 1965... Line 2011...
1965
        DEBUGF  1,"SOCKET_check_owner: %x\n", eax
2011
        DEBUGF  1,"SOCKET_check_owner: %x\n", eax
1966
 
2012
 
1967
        push    ebx
2013
        push    ebx
1968
        mov     ebx, [TASK_BASE]
2014
        mov     ebx, [TASK_BASE]
1969
        mov     ebx, [ecx + TASKDATA.pid]
2015
        mov     ebx, [ebx + TASKDATA.pid]
Line 1970... Line 2016...
1970
        cmp     [eax + SOCKET.PID], ebx
2016
        cmp     [eax + SOCKET.PID], ebx
Line 2048... Line 2094...
2048
        DEBUGF  1,"SOCKET_is_connecting: %x\n", eax
2094
        DEBUGF  1,"SOCKET_is_connecting: %x\n", eax
Line 2049... Line 2095...
2049
 
2095
 
2050
        and     [eax + SOCKET.options], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING)
2096
        and     [eax + SOCKET.options], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING)
Line 2051... Line 2097...
2051
        or      [eax + SOCKET.options], SS_ISCONNECTING
2097
        or      [eax + SOCKET.options], SS_ISCONNECTING
Line 2052... Line 2098...
2052
 
2098
 
2053
        jmp     SOCKET_notify_owner
2099
        jmp     SOCKET_notify
Line 2069... Line 2115...
2069
        DEBUGF  1,"SOCKET_is_connected: %x\n", eax
2115
        DEBUGF  1,"SOCKET_is_connected: %x\n", eax
Line 2070... Line 2116...
2070
 
2116
 
2071
        and     [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING)
2117
        and     [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING)
Line 2072... Line 2118...
2072
        or      [eax + SOCKET.options], SS_ISCONNECTED
2118
        or      [eax + SOCKET.options], SS_ISCONNECTED
Line 2073... Line 2119...
2073
 
2119
 
Line 2091... Line 2137...
2091
        DEBUGF  1,"SOCKET_is_disconnecting: %x\n", eax
2137
        DEBUGF  1,"SOCKET_is_disconnecting: %x\n", eax
Line 2092... Line 2138...
2092
 
2138
 
2093
        and     [eax + SOCKET.options], not (SS_ISCONNECTING)
2139
        and     [eax + SOCKET.options], not (SS_ISCONNECTING)
Line 2094... Line 2140...
2094
        or      [eax + SOCKET.options], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE
2140
        or      [eax + SOCKET.options], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE
Line 2095... Line 2141...
2095
 
2141
 
2096
        jmp     SOCKET_notify_owner
2142
        jmp     SOCKET_notify
Line 2112... Line 2158...
2112
        DEBUGF  1,"SOCKET_is_disconnected: %x\n", eax
2158
        DEBUGF  1,"SOCKET_is_disconnected: %x\n", eax
Line 2113... Line 2159...
2113
 
2159
 
2114
        and     [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING)
2160
        and     [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING)
Line 2115... Line 2161...
2115
        or      [eax + SOCKET.options], SS_CANTRCVMORE + SS_CANTSENDMORE
2161
        or      [eax + SOCKET.options], SS_CANTRCVMORE + SS_CANTSENDMORE
Line 2116... Line 2162...
2116
 
2162
 
2117
        jmp     SOCKET_notify_owner
2163
        jmp     SOCKET_notify
2118
 
2164