Subversion Repositories Kolibri OS

Rev

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

Rev 3261 Rev 3264
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: 3261 $
18
$Revision: 3264 $
Line 19... Line 19...
19
 
19
 
20
 
20
 
21
struct  SOCKET
21
struct  SOCKET
Line 22... Line 22...
22
 
22
 
Line 23... Line 23...
23
        NextPtr                 dd ? ; pointer to next socket in list
23
        NextPtr                 dd ? ; pointer to next socket in list
-
 
24
        PrevPtr                 dd ? ; pointer to previous socket in list
24
        PrevPtr                 dd ? ; pointer to previous socket in list
25
        Number                  dd ? ; socket number
25
        Number                  dd ? ; socket number
26
 
26
 
27
        mutex                   MUTEX
27
        mutex                   MUTEX
28
 
28
 
29
        PID                     dd ? ; process ID
Line 680... Line 681...
680
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .block
681
        get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .block
Line 681... Line 682...
681
 
682
 
682
; Ok, we got a socket ptr
683
; Ok, we got a socket ptr
Line 683... Line 684...
683
        mov     eax, [esi]
684
        mov     eax, [esi]
684
 
685
 
685
; Change PID to that of the current process
686
; Change thread ID to that of the current thread
686
        mov     ebx, [TASK_BASE]
687
        mov     ebx, [TASK_BASE]
Line 687... Line 688...
687
        mov     ebx, [ebx + TASKDATA.pid]
688
        mov     ebx, [ebx + TASKDATA.pid]
688
        mov     [eax + SOCKET.PID], ebx
689
        mov     [eax + SOCKET.TID], ebx
689
 
690
 
690
; Convert it to a socket number
691
; Convert it to a socket number
Line 715... Line 716...
715
        DEBUGF  2,"SOCKET_close: socknum=%u\n", ecx
716
        DEBUGF  2,"SOCKET_close: socknum=%u\n", ecx
Line 716... Line 717...
716
 
717
 
717
        call    SOCKET_num_to_ptr
718
        call    SOCKET_num_to_ptr
Line 718... Line -...
718
        jz      s_error
-
 
719
 
-
 
720
        cmp     [eax + SOCKET.Domain], AF_INET4
-
 
721
        jne     s_error
719
        jz      s_error
722
 
-
 
Line 723... Line -...
723
        cmp     [eax + SOCKET.Protocol], IP_PROTO_UDP
-
 
724
        je      .free
720
 
725
 
-
 
726
        cmp     [eax + SOCKET.Protocol], IP_PROTO_ICMP
721
        mov     dword [esp+32], 0                               ; The socket exists, so we will succeed in closing it.
727
        je      .free
722
 
Line 728... Line 723...
728
 
723
  .socket:
729
        cmp     [eax + SOCKET.Protocol], IP_PROTO_IP
724
        cmp     [eax + SOCKET.Domain], AF_INET4
Line -... Line 725...
-
 
725
        jne     .free
730
        je      .free
726
 
-
 
727
        cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
Line 731... Line 728...
731
 
728
        je      .tcp
732
        cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
729
 
733
        je      .tcp
730
  .free:
Line 734... Line 731...
734
 
731
        call    SOCKET_free
735
        jmp     s_error
732
        ret
Line 736... Line -...
736
 
-
 
737
  .tcp:
-
 
738
        cmp     [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED    ; state must be LISTEN, SYN_SENT or CLOSED
-
 
739
        jb      .free
-
 
740
 
-
 
741
        call    TCP_usrclosed
-
 
742
        call    TCP_output      ;;;; Fixme: is this nescessary??
-
 
743
 
-
 
744
;;; TODO: wait for successfull termination if blocking socket
-
 
745
        mov     dword [esp+32], 0
733
 
Line 746... Line 734...
746
 
734
  .tcp:
747
        ret
735
        cmp     [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED    ; state must be LISTEN, SYN_SENT or CLOSED
Line 836... Line 824...
836
 
824
 
837
        ; Change PID to that of current process
825
        ; Change PID to that of current process
838
        mov     ebx, [TASK_BASE]
826
        mov     ebx, [TASK_BASE]
839
        mov     ebx, [ebx + TASKDATA.pid]
827
        mov     ebx, [ebx + TASKDATA.pid]
-
 
828
        mov     [eax + SOCKET.PID], ebx
840
        mov     [eax + SOCKET.PID], ebx
829
        mov     [eax + SOCKET.TID], ebx         ; currently TID = PID in kolibrios :(
Line 841... Line 830...
841
      @@:
830
      @@:
Line 842... Line 831...
842
 
831
 
Line 970... Line 959...
970
 
959
 
971
        ; Change PID to that of current process
960
        ; Change PID to that of current process
972
        mov     ebx, [TASK_BASE]
961
        mov     ebx, [TASK_BASE]
973
        mov     ebx, [ebx + TASKDATA.pid]
962
        mov     ebx, [ebx + TASKDATA.pid]
-
 
963
        mov     [eax + SOCKET.PID], ebx
974
        mov     [eax + SOCKET.PID], ebx
964
        mov     [eax + SOCKET.TID], ebx         ; currently TID = PID in kolibrios :(
975
      @@:
965
      @@:
Line 976... Line 966...
976
        mov     [eax + SOCKET.snd_proc], SOCKET_send_local_
966
        mov     [eax + SOCKET.snd_proc], SOCKET_send_local_
977
 
967
 
Line 1606... Line 1596...
1606
        or      [eax + SOCKET.state], SS_BLOCKED
1596
        or      [eax + SOCKET.state], SS_BLOCKED
Line 1607... Line 1597...
1607
 
1597
 
1608
        ; Suspend the thread
1598
        ; Suspend the thread
1609
        push    edx
1599
        push    edx
1610
        mov     edx, [TASK_BASE]
-
 
1611
        DEBUGF  1,"SOCKET_block: suspending PID: %u\n", [edx + TASKDATA.pid]
1600
        mov     edx, [TASK_BASE]
-
 
1601
        mov     [edx + TASKDATA.state], 1               ; Suspended
-
 
1602
 
-
 
1603
        ; Remember the thread ID so we can wake it up again
-
 
1604
        mov     edx, [edx + TASKDATA.pid]
-
 
1605
        DEBUGF  1,"SOCKET_block: suspending thread: %u\n", edx
1612
        mov     [edx + TASKDATA.state], 1               ; Suspended
1606
        mov     [eax + SOCKET.TID], edx
Line 1613... Line 1607...
1613
        pop     edx
1607
        pop     edx
1614
 
1608
 
Line 1647... Line 1641...
1647
        push    eax ecx esi
1641
        push    eax ecx esi
Line 1648... Line 1642...
1648
 
1642
 
1649
; socket exists and is of non blocking type.
1643
; socket exists and is of non blocking type.
Line 1650... Line 1644...
1650
; We'll try to flag an event to the thread
1644
; We'll try to flag an event to the thread
1651
 
1645
 
1652
        mov     eax, [eax + SOCKET.PID]
1646
        mov     eax, [eax + SOCKET.TID]
1653
        test    eax, eax
1647
        test    eax, eax
1654
        jz      .done
1648
        jz      .done
Line 1678... Line 1672...
1678
        push    eax ecx esi
1672
        push    eax ecx esi
1679
        ; Clear the 'socket is blocked' flag
1673
        ; Clear the 'socket is blocked' flag
1680
        and     [eax + SOCKET.state], not SS_BLOCKED
1674
        and     [eax + SOCKET.state], not SS_BLOCKED
Line 1681... Line 1675...
1681
 
1675
 
1682
        ; Find the thread's TASK_DATA
1676
        ; Find the thread's TASK_DATA
1683
        mov     eax, [eax + SOCKET.PID]
1677
        mov     eax, [eax + SOCKET.TID]
1684
        test    eax, eax
1678
        test    eax, eax
1685
        jz      .error
1679
        jz      .error
1686
        xor     ecx, ecx
1680
        xor     ecx, ecx
1687
        inc     ecx
1681
        inc     ecx
Line 1767... Line 1761...
1767
 
1761
 
1768
; Fill in PID
1762
; Fill in PID
1769
        mov     ebx, [TASK_BASE]
1763
        mov     ebx, [TASK_BASE]
1770
        mov     ebx, [ebx + TASKDATA.pid]
1764
        mov     ebx, [ebx + TASKDATA.pid]
-
 
1765
        mov     [eax + SOCKET.PID], ebx
Line 1771... Line 1766...
1771
        mov     [eax + SOCKET.PID], ebx
1766
        mov     [eax + SOCKET.TID], ebx         ; currently TID = PID in kolibrios :(
1772
 
1767
 
1773
; init mutex
1768
; init mutex
1774
        pusha
1769
        pusha
Line 2062... Line 2057...
2062
        push    ebx
2057
        push    ebx
2063
        mov     ebx, net_sockets
2058
        mov     ebx, net_sockets
Line 2064... Line 2059...
2064
 
2059
 
2065
  .next_socket:
2060
  .next_socket:
2066
        mov     ebx, [ebx + SOCKET.NextPtr]
-
 
2067
  .test_socket:
2061
        mov     ebx, [ebx + SOCKET.NextPtr]
2068
        test    ebx, ebx
2062
        test    ebx, ebx
Line 2069... Line 2063...
2069
        jz      .done
2063
        jz      .done
2070
 
2064
 
Line 2071... Line 2065...
2071
        cmp     [ebx + SOCKET.PID], edx
2065
        cmp     [ebx + SOCKET.PID], edx
Line 2072... Line 2066...
2072
        jne     .next_socket
2066
        jne     .next_socket
2073
 
-
 
2074
        DEBUGF  1,"SOCKET_process_end: killing socket %x\n", ebx
-
 
2075
 
-
 
2076
        mov     [ebx + SOCKET.PID], 0
-
 
2077
 
-
 
2078
        cmp     [ebx + SOCKET.Protocol], IP_PROTO_TCP
-
 
2079
        je      .tcp
2067
 
2080
 
-
 
2081
; The socket is stateless, just kill it right away!
-
 
2082
 
-
 
2083
        mov     eax, ebx
-
 
2084
        mov     ebx, [ebx + SOCKET.NextPtr]
-
 
2085
        call    SOCKET_free
-
 
2086
        jmp     .test_socket
2068
        DEBUGF  1, "SOCKET_process_end: killing socket %x\n", ebx
2087
 
2069
 
2088
  .tcp:
2070
        mov     [ebx + SOCKET.PID], 0
2089
        push    [ebx + SOCKET.NextPtr]
2071
        mov     eax, ebx
Line 2090... Line 2072...
2090
        mov     eax, ebx
2072
        pusha
2091
        call    TCP_disconnect
2073
        call    SOCKET_close.socket
Line 2092... Line 2074...
2092
        pop     ebx
2074
        popa