Subversion Repositories Kolibri OS

Rev

Rev 3147 | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;  Part of the TCP/IP network stack for KolibriOS                 ;;
  7. ;;                                                                 ;;
  8. ;;   Written by hidnplayr@kolibrios.org,                           ;;
  9. ;;     and Clevermouse.                                            ;;
  10. ;;                                                                 ;;
  11. ;;       Based on code by mike.dld                                 ;;
  12. ;;                                                                 ;;
  13. ;;         GNU GENERAL PUBLIC LICENSE                              ;;
  14. ;;          Version 2, June 1991                                   ;;
  15. ;;                                                                 ;;
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17.  
  18. $Revision: 3228 $
  19.  
  20.  
  21. struct  SOCKET
  22.  
  23.         NextPtr                 dd ? ; pointer to next socket in list
  24.         PrevPtr                 dd ? ; pointer to previous socket in list
  25.         Number                  dd ? ; socket number
  26.  
  27.         mutex                   MUTEX
  28.  
  29.         PID                     dd ? ; application process id
  30.         Domain                  dd ? ; INET/UNIX/..
  31.         Type                    dd ? ; RAW/STREAM/DGRAP
  32.         Protocol                dd ? ; ICMP/IPv4/ARP/TCP/UDP
  33.         errorcode               dd ?
  34.         device                  dd ? ; driver pointer, socket pointer if it's an UNIX socket
  35.  
  36.         options                 dd ?
  37.         state                   dd ?
  38.         backlog                 dw ? ; how many incomming connections that can be queued
  39.  
  40.         snd_proc                dd ?
  41.         rcv_proc                dd ?
  42.  
  43. ends
  44.  
  45. struct  IP_SOCKET               SOCKET
  46.  
  47.         LocalIP                 rd 4 ; network byte order
  48.         RemoteIP                rd 4 ; network byte order
  49.  
  50. ends
  51.  
  52. struct  TCP_SOCKET              IP_SOCKET
  53.  
  54.         LocalPort               dw ? ; network byte order
  55.         RemotePort              dw ? ; network byte order
  56.  
  57.         t_state                 dd ? ; TCB state
  58.         t_rxtshift              db ?
  59.                                 rb 3 ; align
  60.         t_rxtcur                dd ?
  61.         t_dupacks               dd ?
  62.         t_maxseg                dd ?
  63.         t_force                 dd ?
  64.         t_flags                 dd ?
  65.  
  66. ;---------------
  67. ; RFC783 page 21
  68.  
  69. ; send sequence
  70.         SND_UNA                 dd ? ; sequence number of unack'ed sent Packets
  71.         SND_NXT                 dd ? ; next send sequence number to use
  72.         SND_UP                  dd ? ; urgent pointer
  73.         SND_WL1                 dd ? ; window minus one
  74.         SND_WL2                 dd ? ;
  75.         ISS                     dd ? ; initial send sequence number
  76.         SND_WND                 dd ? ; send window
  77.  
  78. ; receive sequence
  79.         RCV_WND                 dd ? ; receive window
  80.         RCV_NXT                 dd ? ; next receive sequence number to use
  81.         RCV_UP                  dd ? ; urgent pointer
  82.         IRS                     dd ? ; initial receive sequence number
  83.  
  84. ;---------------------
  85. ; Additional variables
  86.  
  87. ; receive variables
  88.         RCV_ADV                 dd ?
  89.  
  90. ; retransmit variables
  91.         SND_MAX                 dd ?
  92.  
  93. ; congestion control
  94.         SND_CWND                dd ?
  95.         SND_SSTHRESH            dd ?
  96.  
  97. ;----------------------
  98. ; Transmit timing stuff
  99.         t_idle                  dd ?
  100.         t_rtt                   dd ?
  101.         t_rtseq                 dd ?
  102.         t_srtt                  dd ?
  103.         t_rttvar                dd ?
  104.         t_rttmin                dd ?
  105.         max_sndwnd              dd ?
  106.  
  107. ;-----------------
  108. ; Out-of-band data
  109.         t_oobflags              dd ?
  110.         t_iobc                  dd ?
  111.         t_softerror             dd ?
  112.  
  113.  
  114. ;---------
  115. ; RFC 1323                              ; the order of next 4 elements may not change
  116.  
  117.         SND_SCALE               db ?
  118.         RCV_SCALE               db ?
  119.         requested_s_scale       db ?
  120.         request_r_scale         db ?
  121.  
  122.         ts_recent               dd ?    ; a copy of the most-recent valid timestamp from the other end
  123.         ts_recent_age           dd ?
  124.         last_ack_sent           dd ?
  125.  
  126.  
  127. ;-------
  128. ; Timers
  129.         timer_retransmission    dd ? ; rexmt
  130.         timer_persist           dd ?
  131.         timer_keepalive         dd ? ; keepalive/syn timeout
  132.         timer_timed_wait        dd ? ; also used as 2msl timer
  133.  
  134. ; extra
  135.  
  136.         ts_ecr                  dd ? ; timestamp echo reply
  137.         ts_val                  dd ?
  138.         temp_bits               db ?
  139.  
  140. ends
  141.  
  142. struct  UDP_SOCKET              IP_SOCKET
  143.  
  144.         LocalPort               dw ? ; network byte order
  145.         RemotePort              dw ? ; network byte order
  146.         firstpacket             db ?
  147.  
  148. ends
  149.  
  150.  
  151. struct  ICMP_SOCKET             IP_SOCKET
  152.  
  153.         Identifier              dw ?
  154.  
  155. ends
  156.  
  157.  
  158. struct  RING_BUFFER
  159.  
  160.         start_ptr               dd ? ; Pointer to start of buffer
  161.         end_ptr                 dd ? ; pointer to end of buffer
  162.         read_ptr                dd ? ; Read pointer
  163.         write_ptr               dd ? ; Write pointer
  164.         size                    dd ? ; Number of bytes buffered
  165.  
  166. ends
  167.  
  168. struct  STREAM_SOCKET           TCP_SOCKET
  169.  
  170.         rcv                     RING_BUFFER
  171.         snd                     RING_BUFFER
  172.  
  173. ends
  174.  
  175. struct  socket_queue_entry
  176.  
  177.         data_ptr                dd ?
  178.         buf_ptr                 dd ?
  179.         data_size               dd ?
  180.  
  181. ends
  182.  
  183.  
  184. SOCKETBUFFSIZE          = 4096     ; in bytes
  185.  
  186. SOCKET_QUEUE_SIZE       = 10       ; maximum number ofincoming packets queued for 1 socket
  187. ; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start
  188. SOCKET_QUEUE_LOCATION   = (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue)
  189.  
  190. uglobal
  191.         net_sockets     rd 4
  192.         last_socket_num dd ?
  193.         last_UDP_port   dw ? ; These values give the number of the last used ephemeral port
  194.         last_TCP_port   dw ? ;
  195. endg
  196.  
  197.  
  198. ;-----------------------------------------------------------------
  199. ;
  200. ; SOCKET_init
  201. ;
  202. ;-----------------------------------------------------------------
  203. macro   SOCKET_init {
  204.  
  205.         xor     eax, eax
  206.         mov     edi, net_sockets
  207.         mov     ecx, 5
  208.         rep     stosd
  209.  
  210.        @@:
  211.         pseudo_random eax
  212.         cmp     ax, MIN_EPHEMERAL_PORT
  213.         jb      @r
  214.         cmp     ax, MAX_EPHEMERAL_PORT
  215.         ja      @r
  216.         xchg    al, ah
  217.         mov     [last_UDP_port], ax
  218.  
  219.        @@:
  220.         pseudo_random eax
  221.         cmp     ax, MIN_EPHEMERAL_PORT
  222.         jb      @r
  223.         cmp     ax, MAX_EPHEMERAL_PORT
  224.         ja      @r
  225.         xchg    al, ah
  226.         mov     [last_TCP_port], ax
  227.  
  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.  
  251.  
  252. ;-----------------------------------------------------------------
  253. ;
  254. ; Socket API (function 74)
  255. ;
  256. ;-----------------------------------------------------------------
  257. align 4
  258. sys_socket:
  259.  
  260.         cmp     ebx, 255
  261.         jz      SOCKET_debug
  262.  
  263.         cmp     ebx, .number
  264.         ja      s_error
  265.         jmp     dword [.table + 4*ebx]
  266.  
  267.   .table:
  268.         dd      SOCKET_open     ; 0
  269.         dd      SOCKET_close    ; 1
  270.         dd      SOCKET_bind     ; 2
  271.         dd      SOCKET_listen   ; 3
  272.         dd      SOCKET_connect  ; 4
  273.         dd      SOCKET_accept   ; 5
  274.         dd      SOCKET_send     ; 6
  275.         dd      SOCKET_receive  ; 7
  276.         dd      SOCKET_set_opt  ; 8
  277.         dd      SOCKET_get_opt  ; 9
  278.         dd      SOCKET_pair     ; 10
  279.   .number = ($ - .table) / 4 - 1
  280.  
  281. s_error:
  282.         DEBUGF  1,"socket error\n"
  283.         mov     dword [esp+32], -1
  284.  
  285.         ret
  286.  
  287. ;-----------------------------------------------------------------
  288. ;
  289. ; SOCKET_open
  290. ;
  291. ;  IN:  domain in ecx
  292. ;       type in edx
  293. ;       protocol in esi
  294. ;  OUT: eax is socket num, -1 on error
  295. ;
  296. ;-----------------------------------------------------------------
  297. align 4
  298. SOCKET_open:
  299.  
  300.         DEBUGF  1,"SOCKET_open: domain=%u type=%u protocol=%x\n", ecx, edx, esi
  301.  
  302.         push    ecx edx esi
  303.         call    SOCKET_alloc
  304.         pop     esi edx ecx
  305.         jz      s_error
  306.  
  307.         mov     [esp+32], edi                   ; return socketnumber
  308.  
  309.         mov     [eax + SOCKET.Domain], ecx
  310.         mov     [eax + SOCKET.Type], edx
  311.         mov     [eax + SOCKET.Protocol], esi
  312.  
  313.         cmp     ecx, AF_INET4
  314.         jne     .no_inet4
  315.  
  316.         cmp     edx, SOCK_DGRAM
  317.         je      .udp
  318.  
  319.         cmp     edx, SOCK_STREAM
  320.         je      .tcp
  321.  
  322.         cmp     edx, SOCK_RAW
  323.         je      .raw
  324.  
  325.   .no_inet4:
  326.         cmp     ecx, AF_PPP
  327.         jne     .no_ppp
  328.  
  329.         cmp     esi, PPP_PROTO_ETHERNET
  330.         je      .pppoe
  331.  
  332.   .no_ppp:
  333.         ret
  334.  
  335. align 4
  336.   .raw:
  337.         test    esi, esi       ; IP_PROTO_IP
  338.         jz      .ip
  339.  
  340.         cmp     esi, IP_PROTO_ICMP
  341.         je      .icmp
  342.  
  343.         cmp     esi, IP_PROTO_UDP
  344.         je      .udp
  345.  
  346.         cmp     esi, IP_PROTO_TCP
  347.         je      .tcp
  348.  
  349.         ret
  350.  
  351. align 4
  352.   .udp:
  353.         mov     [eax + SOCKET.Protocol], IP_PROTO_UDP
  354.         mov     [eax + SOCKET.snd_proc], SOCKET_send_udp
  355.         mov     [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
  356.         ret
  357.  
  358. align 4
  359.   .tcp:
  360.         mov     [eax + SOCKET.Protocol], IP_PROTO_TCP
  361.         mov     [eax + SOCKET.snd_proc], SOCKET_send_tcp
  362.         mov     [eax + SOCKET.rcv_proc], SOCKET_receive_stream
  363.  
  364.         TCP_init_socket eax
  365.         ret
  366.  
  367.  
  368. align 4
  369.   .ip:
  370.         mov     [eax + SOCKET.snd_proc], SOCKET_send_ip
  371.         mov     [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
  372.         ret
  373.  
  374.  
  375. align 4
  376.   .icmp:
  377.         mov     [eax + SOCKET.snd_proc], SOCKET_send_icmp
  378.         mov     [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
  379.         ret
  380.  
  381. align 4
  382.   .pppoe:
  383.         push    eax
  384.         init_queue (eax + SOCKET_QUEUE_LOCATION)        ; Set up data receiving queue
  385.         pop     eax
  386.  
  387.         mov     [eax + SOCKET.snd_proc], SOCKET_send_pppoe
  388.         mov     [eax + SOCKET.rcv_proc], SOCKET_receive_dgram
  389.         ret
  390.  
  391.  
  392. ;-----------------------------------------------------------------
  393. ;
  394. ; SOCKET_bind
  395. ;
  396. ;  IN:  socket number in ecx
  397. ;       pointer to sockaddr struct in edx
  398. ;       length of that struct in esi
  399. ;  OUT: 0 on success
  400. ;
  401. ;-----------------------------------------------------------------
  402. align 4
  403. SOCKET_bind:
  404.  
  405.         DEBUGF  1,"SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
  406.  
  407.         call    SOCKET_num_to_ptr
  408.         jz      s_error
  409.  
  410.         cmp     esi, 2
  411.         jb      s_error
  412.  
  413.         cmp     word [edx], AF_INET4
  414.         je      .af_inet4
  415.  
  416.         cmp     word [edx], AF_UNIX
  417.         je      .af_unix
  418.  
  419.         jmp     s_error
  420.  
  421.   .af_unix:
  422.         ; TODO: write code here
  423.  
  424.         mov     dword [esp+32], 0
  425.         ret
  426.  
  427.   .af_inet4:
  428.  
  429.         cmp     esi, 6
  430.         jb      s_error
  431.  
  432.         cmp     [eax + SOCKET.Protocol], IP_PROTO_UDP
  433.         je      .udp
  434.  
  435.         cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
  436.         je      .tcp
  437.  
  438.         jmp     s_error
  439.  
  440.   .tcp:
  441.   .udp:
  442.  
  443.         mov     ebx, [edx + 4]                  ; First, fill in the IP
  444.         test    ebx, ebx                        ; If IP is 0, use default
  445.         jnz     @f
  446.         mov     ebx, [NET_DEFAULT]
  447.         mov     ebx, [IP_LIST + 4*ebx]
  448.        @@:
  449.         mov     [eax + IP_SOCKET.LocalIP], ebx
  450.  
  451.         mov     bx, [edx + 2]                   ; Now fill in the local port if it's still available
  452.         call    SOCKET_check_port
  453.         jz      s_error                         ; ZF is set by socket_check_port, on error
  454.  
  455.         DEBUGF  1,"SOCKET_bind: local ip=%u.%u.%u.%u\n",\
  456.         [eax + IP_SOCKET.LocalIP + 0]:1,[eax + IP_SOCKET.LocalIP + 1]:1,\
  457.         [eax + IP_SOCKET.LocalIP + 2]:1,[eax + IP_SOCKET.LocalIP + 3]:1
  458.  
  459.         mov     dword [esp+32], 0
  460.         ret
  461.  
  462.  
  463.  
  464.  
  465. ;-----------------------------------------------------------------
  466. ;
  467. ; SOCKET_connect
  468. ;
  469. ;  IN:  socket number in ecx
  470. ;       pointer to sockaddr struct in edx
  471. ;       length of that struct in esi
  472. ;  OUT: 0 on success
  473. ;
  474. ;-----------------------------------------------------------------
  475. align 4
  476. SOCKET_connect:
  477.  
  478.         DEBUGF  1,"SOCKET_connect: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
  479.  
  480.         call    SOCKET_num_to_ptr
  481.         jz      s_error
  482.  
  483.         cmp     esi, 8
  484.         jb      s_error
  485.  
  486.         cmp     word [edx], AF_INET4
  487.         je      .af_inet4
  488.  
  489.         jmp     s_error
  490.  
  491.   .af_inet4:
  492.         cmp     [eax + IP_SOCKET.LocalIP], 0
  493.         jne     @f
  494.         push    [IP_LIST]
  495.         pop     [eax + IP_SOCKET.LocalIP]
  496.        @@:
  497.  
  498.         cmp     [eax + SOCKET.Protocol], IP_PROTO_UDP
  499.         je      .udp
  500.  
  501.         cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
  502.         je      .tcp
  503.  
  504.         cmp     [eax + SOCKET.Protocol], IP_PROTO_IP
  505.         je      .ip
  506.  
  507.         cmp     [eax + SOCKET.Protocol], IP_PROTO_ICMP
  508.         je      .ip
  509.  
  510.         jmp     s_error
  511.  
  512. align 4
  513.   .udp:
  514.         pusha
  515.         lea     ecx, [eax + SOCKET.mutex]
  516.         call    mutex_lock
  517.         popa
  518.  
  519.         pushw   [edx + 2]
  520.         pop     [eax + UDP_SOCKET.RemotePort]
  521.  
  522.         pushd   [edx + 4]
  523.         pop     [eax + IP_SOCKET.RemoteIP]
  524.  
  525.         cmp     [eax + UDP_SOCKET.LocalPort], 0
  526.         jne     @f
  527.         call    SOCKET_find_port
  528.        @@:
  529.  
  530.         mov     [eax + UDP_SOCKET.firstpacket], 0
  531.  
  532.         push    eax
  533.         init_queue (eax + SOCKET_QUEUE_LOCATION)        ; Set up data receiving queue
  534.         pop     eax
  535.  
  536.         lea     ecx, [eax + SOCKET.mutex]
  537.         call    mutex_unlock
  538.  
  539.         mov     dword [esp+32], 0
  540.         ret
  541.  
  542. align 4
  543.   .tcp:
  544.         pusha
  545.         lea     ecx, [eax + SOCKET.mutex]
  546.         call    mutex_lock
  547.         popa
  548.  
  549.         pushw   [edx + 2]
  550.         pop     [eax + TCP_SOCKET.RemotePort]
  551.  
  552.         pushd   [edx + 4]
  553.         pop     [eax + IP_SOCKET.RemoteIP]
  554.  
  555.         cmp     [eax + TCP_SOCKET.LocalPort], 0
  556.         jne     @f
  557.         call    SOCKET_find_port
  558.        @@:
  559.  
  560.         mov     [eax + TCP_SOCKET.timer_persist], 0
  561.         mov     [eax + TCP_SOCKET.t_state], TCPS_SYN_SENT
  562.  
  563.         push    [TCP_sequence_num]
  564.         add     [TCP_sequence_num], 6400
  565.         pop     [eax + TCP_SOCKET.ISS]
  566.         mov     [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init
  567.  
  568.  
  569.         TCP_sendseqinit eax
  570.  
  571. ;        mov     [ebx + TCP_SOCKET.timer_retransmission],   ;; todo: create macro to set retransmission timer
  572.  
  573.         mov     ebx, eax
  574.  
  575.         lea     eax, [ebx + STREAM_SOCKET.snd]
  576.         call    SOCKET_ring_create
  577.  
  578.         lea     eax, [ebx + STREAM_SOCKET.rcv]
  579.         call    SOCKET_ring_create
  580.  
  581.         pusha
  582.         lea     ecx, [ebx + SOCKET.mutex]
  583.         call    mutex_unlock
  584.         popa
  585.  
  586.         mov     eax, ebx
  587.         call    TCP_output
  588.  
  589. ;;; TODO: wait for successfull connection if blocking socket
  590.  
  591.         mov     dword [esp+32], 0
  592.         ret
  593.  
  594. align 4
  595.   .ip:
  596.         pusha
  597.         lea     ecx, [eax + SOCKET.mutex]
  598.         call    mutex_lock
  599.         popa
  600.  
  601.         pushd   [edx + 4]
  602.         pop     [eax + IP_SOCKET.RemoteIP]
  603.  
  604.         push    eax
  605.         init_queue (eax + SOCKET_QUEUE_LOCATION)        ; Set up data receiving queue
  606.         pop     eax
  607.  
  608.         lea     ecx, [eax + SOCKET.mutex]
  609.         call    mutex_unlock
  610.  
  611.         mov     dword [esp+32], 0
  612.         ret
  613.  
  614.  
  615. ;-----------------------------------------------------------------
  616. ;
  617. ; SOCKET_listen
  618. ;
  619. ;  IN:  socket number in ecx
  620. ;       backlog in edx
  621. ;  OUT: eax is socket num, -1 on error
  622. ;
  623. ;-----------------------------------------------------------------
  624. align 4
  625. SOCKET_listen:
  626.  
  627.         DEBUGF  1,"SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx
  628.  
  629.         call    SOCKET_num_to_ptr
  630.         jz      s_error
  631.  
  632.         cmp     [eax + SOCKET.Domain], AF_INET4
  633.         jne     s_error
  634.  
  635.         cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
  636.         jne     s_error
  637.  
  638.         cmp     [eax + TCP_SOCKET.LocalPort], 0
  639.         je      s_error
  640.  
  641.         cmp     [eax + IP_SOCKET.LocalIP], 0
  642.         jne     @f
  643.         push    [IP_LIST]
  644.         pop     [eax + IP_SOCKET.LocalIP]
  645.        @@:
  646.  
  647.         cmp     edx, MAX_backlog
  648.         jbe     @f
  649.         mov     edx, MAX_backlog
  650.        @@:
  651.  
  652.         mov     [eax + SOCKET.backlog], dx
  653.         or      [eax + SOCKET.options], SO_ACCEPTCON
  654.         mov     [eax + TCP_SOCKET.t_state], TCPS_LISTEN
  655.         mov     [eax + TCP_SOCKET.timer_keepalive], 0           ; disable keepalive timer
  656.  
  657.         push    eax
  658.         init_queue (eax + SOCKET_QUEUE_LOCATION)                ; Set up sockets queue
  659.         pop     eax
  660.  
  661.         mov     dword [esp+32], 0
  662.  
  663.         ret
  664.  
  665.  
  666. ;-----------------------------------------------------------------
  667. ;
  668. ; SOCKET_accept
  669. ;
  670. ;  IN:  socket number in ecx
  671. ;       addr in edx
  672. ;       addrlen in esi
  673. ;  OUT: eax is socket num, -1 on error
  674. ;
  675. ;-----------------------------------------------------------------
  676. align 4
  677. SOCKET_accept:
  678.  
  679.         DEBUGF  1,"SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
  680.  
  681.         call    SOCKET_num_to_ptr
  682.         jz      s_error
  683.  
  684.         test    [eax + SOCKET.options], SO_ACCEPTCON
  685.         jz      s_error
  686.  
  687.         cmp     [eax + SOCKET.Domain], AF_INET4
  688.         jne     s_error
  689.  
  690.         cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
  691.         jne     s_error
  692.  
  693.   .loop:
  694.         get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .block
  695.  
  696. ; Ok, we got a socket ptr
  697.         mov     eax, [esi]
  698.  
  699. ; Change PID to that of the current process
  700.         mov     ebx, [TASK_BASE]
  701.         mov     ebx, [ebx + TASKDATA.pid]
  702.         mov     [eax + SOCKET.PID], ebx
  703.  
  704. ; Convert it to a socket number
  705.         call    SOCKET_ptr_to_num
  706.         jz      s_error
  707. ; and return it to caller
  708.         mov     [esp+32], eax
  709.         ret
  710.  
  711.   .block:
  712.         SOCKET_block    eax, .loop, s_error
  713.  
  714. ;-----------------------------------------------------------------
  715. ;
  716. ; SOCKET_close
  717. ;
  718. ;  IN:  socket number in ecx
  719. ;  OUT: eax is socket num, -1 on error
  720. ;
  721. ;-----------------------------------------------------------------
  722. align 4
  723. SOCKET_close:
  724.  
  725.         DEBUGF  1,"SOCKET_close: %u\n", ecx
  726.  
  727.         call    SOCKET_num_to_ptr
  728.         jz      s_error
  729.  
  730.         cmp     [eax + SOCKET.Domain], AF_INET4
  731.         jne     s_error
  732.  
  733.         cmp     [eax + SOCKET.Protocol], IP_PROTO_UDP
  734.         je      .free
  735.  
  736.         cmp     [eax + SOCKET.Protocol], IP_PROTO_ICMP
  737.         je      .free
  738.  
  739.         cmp     [eax + SOCKET.Protocol], IP_PROTO_IP
  740.         je      .free
  741.  
  742.         cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
  743.         je      .tcp
  744.  
  745.         jmp     s_error
  746.  
  747.   .tcp:
  748.         cmp     [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED    ; state must be LISTEN, SYN_SENT or CLOSED
  749.         jb      .free
  750.  
  751.         call    TCP_usrclosed
  752.         call    TCP_output      ;;;; Fixme: is this nescessary??
  753.  
  754. ;;; TODO: wait for successfull termination if blocking socket
  755.         mov     dword [esp+32], 0
  756.  
  757.         ret
  758.  
  759.   .free:
  760.         call    SOCKET_free
  761.         mov     dword [esp+32], 0
  762.  
  763.         ret
  764.  
  765.  
  766. ;-----------------------------------------------------------------
  767. ;
  768. ; SOCKET_receive
  769. ;
  770. ;  IN:  socket number in ecx
  771. ;       addr to buffer in edx
  772. ;       length of buffer in esi
  773. ;       flags in edi
  774. ;  OUT: eax is number of bytes copied, -1 on error
  775. ;
  776. ;-----------------------------------------------------------------
  777. align 4
  778. SOCKET_receive:
  779.  
  780.         DEBUGF  1,"SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi
  781.  
  782.         call    SOCKET_num_to_ptr
  783.         jz      s_error
  784.  
  785.         jmp     [eax + SOCKET.rcv_proc]
  786.  
  787.  
  788. align 4
  789. SOCKET_receive_dgram:
  790.  
  791.         DEBUGF  1,"SOCKET_receive: DGRAM\n"
  792.  
  793.         mov     ebx, esi
  794.         mov     edi, edx                                        ; addr to buffer
  795.  
  796.   .loop:
  797.         get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, .block      ; destroys esi and ecx
  798.  
  799.         mov     ecx, [esi + socket_queue_entry.data_size]
  800.         DEBUGF  1,"SOCKET_receive: %u bytes data\n", ecx
  801.  
  802.         cmp     ecx, ebx
  803.         ja      .too_small
  804.  
  805.         push    [esi + socket_queue_entry.buf_ptr]              ; save the buffer addr so we can clear it later
  806.         mov     esi, [esi + socket_queue_entry.data_ptr]
  807.         DEBUGF  1,"SOCKET_receive: Source buffer=%x real addr=%x\n", [esp], esi
  808.         mov     [esp+32+4], ecx                                 ; return number of bytes copied
  809.  
  810. ; copy the data
  811.         shr     ecx, 1
  812.         jnc     .nb
  813.         movsb
  814.   .nb:
  815.         shr     ecx, 1
  816.         jnc     .nw
  817.         movsw
  818.   .nw:
  819.         test    ecx, ecx
  820.         jz      .nd
  821.         rep     movsd
  822.   .nd:
  823.  
  824.         call    kernel_free                                     ; remove the packet
  825.         ret
  826.  
  827.   .too_small:
  828.  
  829.         DEBUGF  1,"SOCKET_receive: Buffer too small\n"
  830.         jmp     s_error
  831.  
  832.   .block:
  833.         SOCKET_block    eax, .loop, s_error
  834.  
  835.  
  836. align 4
  837. SOCKET_receive_stream:
  838.  
  839.         DEBUGF  1,"SOCKET_receive: STREAM\n"
  840.  
  841.         mov     ecx, esi
  842.         mov     edi, edx
  843.         xor     edx, edx
  844.         add     eax, STREAM_SOCKET.rcv
  845.   .loop:
  846.         cmp     [eax + RING_BUFFER.size], 0
  847.         je      .block
  848.         call    SOCKET_ring_read
  849.         call    SOCKET_ring_free
  850.  
  851.         mov     [esp+32], ecx                                   ; return number of bytes copied
  852.         ret
  853.  
  854.   .block:
  855.         SOCKET_block    (eax - STREAM_SOCKET.rcv), .loop, s_error
  856.  
  857.  
  858. ;-----------------------------------------------------------------
  859. ;
  860. ; SOCKET_send
  861. ;
  862. ;
  863. ;  IN:  socket number in ecx
  864. ;       pointer to data in edx
  865. ;       datalength in esi
  866. ;       flags in edi
  867. ;  OUT: -1 on error
  868. ;
  869. ;-----------------------------------------------------------------
  870. align 4
  871. SOCKET_send:
  872.  
  873.         DEBUGF  1,"SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi
  874.  
  875.         call    SOCKET_num_to_ptr
  876.         jz      s_error
  877.  
  878.         mov     ecx, esi
  879.         mov     esi, edx
  880.  
  881.         jmp     [eax + SOCKET.snd_proc]
  882.  
  883.  
  884. align 4
  885. SOCKET_send_udp:
  886.  
  887.         DEBUGF  1,"SOCKET_send: UDP\n"
  888.  
  889.         mov     [esp+32], ecx
  890.         call    UDP_output
  891.         cmp     eax, -1
  892.         je      s_error
  893.         ret
  894.  
  895.  
  896. align 4
  897. SOCKET_send_tcp:
  898.  
  899.         DEBUGF  1,"SOCKET_send: TCP\n"
  900.  
  901.         push    eax
  902.         add     eax, STREAM_SOCKET.snd
  903.         call    SOCKET_ring_write
  904.         pop     eax
  905.  
  906.         mov     [esp+32], ecx
  907.  
  908.         call    TCP_output
  909.         ret
  910.  
  911.  
  912. align 4
  913. SOCKET_send_ip:
  914.  
  915.         DEBUGF  1,"SOCKET_send: IPv4\n"
  916.  
  917.         mov     [esp+32], ecx
  918.         call    IPv4_output_raw
  919.         cmp     eax, -1
  920.         je      s_error
  921.         ret
  922.  
  923.  
  924. align 4
  925. SOCKET_send_icmp:
  926.  
  927.         DEBUGF  1,"SOCKET_send: ICMP\n"
  928.  
  929.         mov     [esp+32], ecx
  930.         call    ICMP_output_raw
  931.         cmp     eax, -1
  932.         je      s_error
  933.         ret
  934.  
  935.  
  936. align 4
  937. SOCKET_send_pppoe:
  938.  
  939.         DEBUGF  1,"SOCKET_send: PPPoE\n"
  940.  
  941.         mov     [esp+32], ecx
  942.         mov     ebx, [eax + SOCKET.device]
  943.  
  944.         call    PPPoE_discovery_output
  945.         cmp     eax, -1
  946.         je      s_error
  947.         ret
  948.  
  949.  
  950.  
  951. align 4
  952. SOCKET_send_unix:
  953.  
  954.         DEBUGF  1,"SOCKET_send: UNIX\n"
  955.  
  956.         call    SOCKET_check
  957.         jz      s_error
  958.         mov     eax, [eax + SOCKET.device]
  959.         call    SOCKET_check
  960.         jz      s_error
  961.  
  962.         push    eax
  963.         add     eax, STREAM_SOCKET.rcv
  964.         call    SOCKET_ring_write
  965.         pop     eax
  966.  
  967.         mov     [esp+32], ecx
  968.  
  969.         call    SOCKET_notify_owner
  970.  
  971.         ret
  972.  
  973.  
  974. ;-----------------------------------------------------------------
  975. ;
  976. ; SOCKET_get_options
  977. ;
  978. ;  IN:  ecx = socket number
  979. ;       edx = pointer to the options:
  980. ;               dd      level, optname, optval, optlen
  981. ;  OUT: -1 on error
  982. ;
  983. ; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP.
  984. ; TODO: find best way to notify that send()'ed data were acknowledged
  985. ; Also pseudo-optname -3 is valid and returns socket state, one of TCPS_*.
  986. ;
  987. ;-----------------------------------------------------------------
  988. align 4
  989. SOCKET_get_opt:
  990.  
  991.         DEBUGF  1,"SOCKET_get_opt\n"
  992.  
  993.         call    SOCKET_num_to_ptr
  994.         jz      s_error
  995.  
  996.         cmp     dword [edx], IP_PROTO_TCP
  997.         jne     s_error
  998.         cmp     dword [edx+4], -2
  999.         je      @f
  1000.         cmp     dword [edx+4], -3
  1001.         jne     s_error
  1002. @@:
  1003. ;        mov     eax, [edx+12]
  1004. ;        test    eax, eax
  1005. ;        jz      .fail
  1006. ;        cmp     dword [eax], 4
  1007. ;        mov     dword [eax], 4
  1008. ;        jb      .fail
  1009. ;        stdcall net_socket_num_to_addr, ecx
  1010. ;        test    eax, eax
  1011. ;        jz      .fail
  1012. ;        ; todo: check that eax is really TCP socket
  1013. ;        mov     ecx, [eax + TCP_SOCKET.last_ack_number]
  1014. ;        cmp     dword [edx+4], -2
  1015. ;        jz      @f
  1016. ;        mov     ecx, [eax + TCP_SOCKET.state]
  1017. @@:
  1018.         mov     eax, [edx+8]
  1019.         test    eax, eax
  1020.         jz      @f
  1021.         mov     [eax], ecx
  1022. @@:
  1023.         mov     dword [esp+32], 0
  1024.         ret
  1025.  
  1026.  
  1027.  
  1028. ;-----------------------------------------------------------------
  1029. ;
  1030. ; SOCKET_set_options
  1031. ;
  1032. ;  IN:  ecx = socket number
  1033. ;       edx = pointer to the options:
  1034. ;               dd      level, optname, optlen, optval
  1035. ;  OUT: -1 on error
  1036. ;
  1037. ;-----------------------------------------------------------------
  1038. align 4
  1039. SOCKET_set_opt:
  1040.  
  1041.         DEBUGF  1,"SOCKET_set_opt\n"
  1042.  
  1043.         call    SOCKET_num_to_ptr
  1044.         jz      s_error
  1045.  
  1046.         cmp     dword [edx], SOL_SOCKET
  1047.         jne     s_error
  1048.  
  1049.         cmp     dword [edx+4], SO_BINDTODEVICE
  1050.         je      .bind
  1051.  
  1052.         cmp     dword [edx+4], SO_BLOCK
  1053.         je      .block
  1054.  
  1055.         jmp     s_error
  1056.  
  1057.   .bind:
  1058.         cmp     dword [edx+8], 0
  1059.         je      .unbind
  1060.  
  1061.         movzx   edx, byte [edx + 9]
  1062.         cmp     edx, MAX_NET_DEVICES
  1063.         ja      s_error
  1064.  
  1065.         mov     edx, [NET_DRV_LIST + 4*edx]
  1066.         test    edx, edx
  1067.         jz      s_error
  1068.         mov     [eax + SOCKET.device], edx
  1069.  
  1070.         DEBUGF  1,"SOCKET_set_opt: Bound socket %x to device %x\n",eax, edx
  1071.  
  1072.         mov     dword [esp+32], 0       ; success!
  1073.         ret
  1074.  
  1075.   .unbind:
  1076.         mov     [eax + SOCKET.device], 0
  1077.  
  1078.         mov     dword [esp+32], 0       ; success!
  1079.         ret
  1080.  
  1081.   .block:
  1082.         cmp     dword [edx+8], 0
  1083.         je      .unblock
  1084.  
  1085.         or      [eax + SOCKET.options], SO_BLOCK
  1086.  
  1087.         mov     dword [esp+32], 0       ; success!
  1088.         ret
  1089.  
  1090.   .unblock:
  1091.         and     [eax + SOCKET.options], not SO_BLOCK
  1092.  
  1093.         mov     dword [esp+32], 0       ; success!
  1094.         ret
  1095.  
  1096.  
  1097.  
  1098. ;-----------------------------------------------------------------
  1099. ;
  1100. ; SOCKET_pair
  1101. ;
  1102. ; Allocates a pair of linked UNIX domain sockets
  1103. ;
  1104. ; IN: /
  1105. ; OUT: eax is socket1 num, -1 on error
  1106. ;      ebx is socket2 num
  1107. ;
  1108. ;-----------------------------------------------------------------
  1109. align 4
  1110. SOCKET_pair:
  1111.  
  1112.         DEBUGF  1,"SOCKET_pair\n"
  1113.  
  1114.         call    SOCKET_alloc
  1115.         jz      s_error
  1116.         mov     [esp+32], edi   ; application's eax
  1117.  
  1118.         mov     [eax + SOCKET.Domain], AF_UNIX
  1119.         mov     [eax + SOCKET.Type], SOCK_STREAM
  1120.         mov     [eax + SOCKET.Protocol], 0              ;;; CHECKME
  1121.         mov     [eax + SOCKET.snd_proc], SOCKET_send_unix
  1122.         mov     [eax + SOCKET.rcv_proc], SOCKET_receive_stream
  1123.         mov     ebx, eax
  1124.  
  1125.         call    SOCKET_alloc
  1126.         jz      .error
  1127.         mov     [esp+24], edi   ; application's ebx
  1128.  
  1129.         mov     [eax + SOCKET.Domain], AF_UNIX
  1130.         mov     [eax + SOCKET.Type], SOCK_STREAM
  1131.         mov     [eax + SOCKET.Protocol], 0              ;;; CHECKME
  1132.         mov     [eax + SOCKET.snd_proc], SOCKET_send_unix
  1133.         mov     [eax + SOCKET.rcv_proc], SOCKET_receive_stream
  1134.  
  1135.         ; Link the two sockets to eachother
  1136.         mov     [eax + SOCKET.device], ebx
  1137.         mov     [ebx + SOCKET.device], eax
  1138.  
  1139.         lea     eax, [eax + STREAM_SOCKET.rcv]
  1140.         call    SOCKET_ring_create
  1141.  
  1142.         lea     eax, [ebx + STREAM_SOCKET.rcv]
  1143.         call    SOCKET_ring_create
  1144.         pop     eax
  1145.  
  1146.  
  1147.  
  1148.         ret
  1149.  
  1150.   .error:
  1151.         mov     eax, ebx
  1152.         call    SOCKET_free
  1153.         jmp     s_error
  1154.  
  1155.  
  1156.  
  1157. ;-----------------------------------------------------------------
  1158. ;
  1159. ; SOCKET_debug
  1160. ;
  1161. ;  Copies socket variables to application buffer
  1162. ;
  1163. ;  IN:  ecx = socket number
  1164. ;       edx = pointer to buffer
  1165. ;
  1166. ;  OUT: -1 on error
  1167. ;-----------------------------------------------------------------
  1168. align 4
  1169. SOCKET_debug:
  1170.  
  1171. ;        DEBUGF  1,"SOCKET_debug\n"
  1172.  
  1173.         mov     edi, edx
  1174.  
  1175.         test    ecx, ecx
  1176.         jz      .returnall
  1177.  
  1178.         call    SOCKET_num_to_ptr
  1179.         jz      s_error
  1180.  
  1181.         mov     esi, eax
  1182.         mov     ecx, SOCKETBUFFSIZE/4
  1183.         rep     movsd
  1184.  
  1185.         mov     dword [esp+32], 0
  1186.         ret
  1187.  
  1188.   .returnall:
  1189.         mov     ebx, net_sockets
  1190.   .next_socket:
  1191.         mov     ebx, [ebx + SOCKET.NextPtr]
  1192.         test    ebx, ebx
  1193.         jz      .done
  1194.         mov     eax, [ebx + SOCKET.Number]
  1195.         stosd
  1196.         jmp     .next_socket
  1197.   .done:
  1198.         xor     eax, eax
  1199.         stosd
  1200.  
  1201.         mov     dword [esp+32], 0
  1202.         ret
  1203.  
  1204.  
  1205. ;-----------------------------------------------------------------
  1206. ;
  1207. ; SOCKET_find_port
  1208. ;
  1209. ; Fills in the local port number for TCP and UDP sockets
  1210. ; This procedure always works because the number of sockets is
  1211. ; limited to a smaller number then the number of possible ports
  1212. ;
  1213. ;  IN:  eax = socket pointer
  1214. ;  OUT: /
  1215. ;
  1216. ;-----------------------------------------------------------------
  1217. align 4
  1218. SOCKET_find_port:
  1219.  
  1220.         DEBUGF  1,"SOCKET_find_port\n"
  1221.  
  1222.         push    ebx esi ecx
  1223.  
  1224.         cmp     [eax + SOCKET.Protocol], IP_PROTO_UDP
  1225.         je      .udp
  1226.  
  1227.         cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
  1228.         je      .tcp
  1229.  
  1230.         pop     ecx esi ebx
  1231.         ret
  1232.  
  1233.   .udp:
  1234.         mov     bx, [last_UDP_port]
  1235.         call    .findit
  1236.         mov     [last_UDP_port], bx
  1237.  
  1238.         pop     ecx esi ebx
  1239.         ret
  1240.  
  1241.   .tcp:
  1242.         mov     bx, [last_TCP_port]
  1243.         call    .findit
  1244.         mov     [last_TCP_port], bx
  1245.  
  1246.         pop     ecx esi ebx
  1247.         ret
  1248.  
  1249.  
  1250.   .restart:
  1251.         mov     bx, MIN_EPHEMERAL_PORT_N
  1252.   .findit:
  1253.         cmp     bx, MAX_EPHEMERAL_PORT_N
  1254.         je      .restart
  1255.  
  1256.         add     bh, 1
  1257.         adc     bl, 0
  1258.  
  1259.         call    SOCKET_check_port
  1260.         jz      .findit
  1261.         ret
  1262.  
  1263.  
  1264.  
  1265. ;-----------------------------------------------------------------
  1266. ;
  1267. ; SOCKET_check_port (to be used with AF_INET only!)
  1268. ;
  1269. ; Checks if a local port number is unused
  1270. ; If the proposed port number is unused, it is filled in in the socket structure
  1271. ;
  1272. ;  IN:  eax = socket ptr (to find out if its a TCP/UDP socket)
  1273. ;        bx = proposed socket number (network byte order)
  1274. ;
  1275. ;  OUT:  ZF = set on error
  1276. ;
  1277. ;-----------------------------------------------------------------
  1278. align 4
  1279. SOCKET_check_port:
  1280.  
  1281.         DEBUGF  1,"SOCKET_check_port: "
  1282.  
  1283.         mov     ecx, [eax + SOCKET.Protocol]
  1284.         mov     edx, [eax + IP_SOCKET.LocalIP]
  1285.         mov     esi, net_sockets
  1286.  
  1287.   .next_socket:
  1288.         mov     esi, [esi + SOCKET.NextPtr]
  1289.         or      esi, esi
  1290.         jz      .port_ok
  1291.  
  1292.         cmp     [esi + SOCKET.Protocol], ecx
  1293.         jne     .next_socket
  1294.  
  1295.         cmp     [esi + IP_SOCKET.LocalIP], edx
  1296.         jne     .next_socket
  1297.  
  1298.         cmp     [esi + UDP_SOCKET.LocalPort], bx
  1299.         jne     .next_socket
  1300.  
  1301.         DEBUGF  1,"local port %x already in use\n", bx  ; FIXME: find a way to print big endian values with debugf
  1302.         ret
  1303.  
  1304.   .port_ok:
  1305.         DEBUGF  1,"local port %x is free\n", bx         ; FIXME: find a way to print big endian values with debugf
  1306.         mov     [eax + UDP_SOCKET.LocalPort], bx
  1307.         or      bx, bx                                  ; clear the zero-flag
  1308.         ret
  1309.  
  1310.  
  1311.  
  1312. ;-----------------------------------------------------------------
  1313. ;
  1314. ; SOCKET_input
  1315. ;
  1316. ; Updates a (stateless) socket with received data
  1317. ;
  1318. ; Note: the mutex should already be set !
  1319. ;
  1320. ;  IN:  eax = socket ptr
  1321. ;       ecx = data size
  1322. ;       esi = ptr to data
  1323. ;       [esp] = ptr to buf
  1324. ;       [esp + 4] = buf size
  1325. ;
  1326. ;  OUT: /
  1327. ;
  1328. ;-----------------------------------------------------------------
  1329. align 4
  1330. SOCKET_input:
  1331.  
  1332.         DEBUGF  1,"SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx
  1333.  
  1334.         mov     [esp+4], ecx
  1335.         push    esi
  1336.         mov     esi, esp
  1337.  
  1338.         add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, SOCKET_input.full
  1339.  
  1340.         DEBUGF  1,"SOCKET_input: queued packet successfully\n"
  1341.         add     esp, sizeof.socket_queue_entry
  1342.  
  1343.         pusha
  1344.         lea     ecx, [eax + SOCKET.mutex]
  1345.         call    mutex_unlock
  1346.         popa
  1347.  
  1348.         jmp     SOCKET_notify_owner
  1349.  
  1350.   .full:
  1351.         DEBUGF  2,"SOCKET_input: socket %x is full!\n", eax
  1352.  
  1353.         pusha
  1354.         lea     ecx, [eax + SOCKET.mutex]
  1355.         call    mutex_unlock
  1356.         popa
  1357.  
  1358.         call    kernel_free
  1359.         add     esp, 8
  1360.  
  1361.         ret
  1362.  
  1363.  
  1364. ;--------------------------
  1365. ;
  1366. ; eax = ptr to ring struct (just a buffer of the right size)
  1367. ;
  1368. align 4
  1369. SOCKET_ring_create:
  1370.  
  1371.         push    esi
  1372.         mov     esi, eax
  1373.  
  1374.         push    edx
  1375.         stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SW
  1376.         pop     edx
  1377.  
  1378.         DEBUGF  1,"SOCKET_ring_created: %x\n", eax
  1379.         mov     [esi + RING_BUFFER.start_ptr], eax
  1380.         mov     [esi + RING_BUFFER.write_ptr], eax
  1381.         mov     [esi + RING_BUFFER.read_ptr], eax
  1382.         mov     [esi + RING_BUFFER.size], 0
  1383.         add     eax, SOCKET_MAXDATA
  1384.         mov     [esi + RING_BUFFER.end_ptr], eax
  1385.         mov     eax, esi
  1386.         pop     esi
  1387.  
  1388.         ret
  1389.  
  1390. ;-----------------------------------------------------------------
  1391. ;
  1392. ; SOCKET_ring_write
  1393. ;
  1394. ; Adds data to a stream socket, and updates write pointer and size
  1395. ;
  1396. ;  IN:  eax = ptr to ring struct
  1397. ;       ecx = data size
  1398. ;       esi = ptr to data
  1399. ;
  1400. ;  OUT: ecx = number of bytes stored
  1401. ;
  1402. ;-----------------------------------------------------------------
  1403. align 4
  1404. SOCKET_ring_write:
  1405.  
  1406.         DEBUGF  1,"SOCKET_ring_write: ringbuff=%x ptr=%x size=%u\n", eax, esi, ecx
  1407.  
  1408.         add     [eax + RING_BUFFER.size], ecx
  1409.         jc      .way_too_large
  1410.         cmp     [eax + RING_BUFFER.size], SOCKET_MAXDATA
  1411.         ja      .too_large
  1412.  
  1413.   .copy:
  1414.         mov     edi, [eax + RING_BUFFER.write_ptr]
  1415.         DEBUGF  2,"SOCKET_ring_write: %u bytes from %x to %x\n", ecx, esi, edi
  1416.  
  1417.         push    ecx
  1418.         shr     ecx, 1
  1419.         jnc     .nb
  1420.         movsb
  1421.   .nb:
  1422.         shr     ecx, 1
  1423.         jnc     .nw
  1424.         movsw
  1425.   .nw:
  1426.         test    ecx, ecx
  1427.         jz      .nd
  1428.         rep     movsd
  1429.   .nd:
  1430.         pop     ecx
  1431.  
  1432.         cmp     edi, [eax + RING_BUFFER.end_ptr]
  1433.         jae     .wrap
  1434.         mov     [eax + RING_BUFFER.write_ptr], edi
  1435.  
  1436.         ret
  1437.  
  1438.   .wrap:
  1439.         sub     edi, SOCKET_MAXDATA
  1440.         mov     [eax + RING_BUFFER.write_ptr], edi
  1441.  
  1442.         ret
  1443.  
  1444.   .too_large:                                                           ; update size, we will fill buffer completely
  1445.         sub     [eax + RING_BUFFER.size], SOCKET_MAXDATA
  1446.         sub     ecx, [eax + RING_BUFFER.size]
  1447.         mov     [eax + RING_BUFFER.size], SOCKET_MAXDATA
  1448.         ja      .copy
  1449.  
  1450.   .full:
  1451.         DEBUGF  2,"SOCKET_ring_write: ring buffer is full!\n"
  1452.         xor     ecx, ecx
  1453.         ret
  1454.  
  1455.   .way_too_large:
  1456.         sub     [eax + RING_BUFFER.size], ecx
  1457.         mov     ecx, SOCKET_MAXDATA
  1458.         sub     ecx, [eax + RING_BUFFER.size]
  1459.         ja      .copy
  1460.         jmp     .full
  1461.  
  1462.  
  1463.  
  1464. ;-----------------------------------------------------------------
  1465. ;
  1466. ; SOCKET_ring_read
  1467. ;
  1468. ;  IN:  eax = ring struct ptr
  1469. ;       ecx = bytes to read
  1470. ;       edx = offset
  1471. ;       edi = ptr to buffer start
  1472. ;
  1473. ;  OUT: eax = unchanged
  1474. ;       ecx = number of bytes read (0 on error)
  1475. ;       edx = destroyed
  1476. ;       esi = destroyed
  1477. ;       edi = ptr to buffer end
  1478. ;
  1479. ;-----------------------------------------------------------------
  1480. align 4
  1481. SOCKET_ring_read:
  1482.  
  1483.         DEBUGF  1,"SOCKET_ring_read: ringbuff=%x ptr=%x size=%u offset=%x\n", eax, edi, ecx, edx
  1484.  
  1485.         mov     esi, [eax + RING_BUFFER.read_ptr]
  1486.         add     esi, edx                                        ; esi = start_ptr + offset
  1487.  
  1488.         neg     edx
  1489.         add     edx, [eax + RING_BUFFER.size]                   ; edx = snd.size - offset
  1490.         jle     .no_data_at_all
  1491.  
  1492.         cmp     ecx, edx
  1493.         ja      .less_data
  1494.  
  1495.   .copy:
  1496.         DEBUGF  2,"SOCKET_ring_read: %u bytes from %x to %x\n", ecx, esi, edi
  1497.         push    ecx
  1498.         shr     ecx, 1
  1499.         jnc     .nb
  1500.         movsb
  1501.   .nb:
  1502.         shr     ecx, 1
  1503.         jnc     .nw
  1504.         movsw
  1505.   .nw:
  1506.         test    ecx, ecx
  1507.         jz      .nd
  1508.         rep     movsd
  1509.   .nd:
  1510.         pop     ecx
  1511.         ret
  1512.  
  1513.   .no_data_at_all:
  1514.         DEBUGF  1,"SOCKET_ring_read: no data at all!\n"
  1515.         xor     ecx, ecx
  1516.         ret
  1517.  
  1518.   .less_data:
  1519.         mov     ecx, edx
  1520.         jmp     .copy
  1521.  
  1522.  
  1523. ;-----------------------------------------------------------------
  1524. ;
  1525. ; SOCKET_ring_free
  1526. ;
  1527. ; Free's some bytes from the ringbuffer
  1528. ;
  1529. ;  IN:  eax = ptr to ring struct
  1530. ;       ecx = data size
  1531. ;
  1532. ;  OUT: ecx = number of bytes free-ed
  1533. ;
  1534. ;-----------------------------------------------------------------
  1535. align 4
  1536. SOCKET_ring_free:
  1537.  
  1538.         DEBUGF  1,"SOCKET_ring_free: %u bytes from ring %x\n", ecx, eax
  1539.  
  1540.         sub     [eax + RING_BUFFER.size], ecx
  1541.         jb      .error
  1542.         add     [eax + RING_BUFFER.read_ptr], ecx
  1543.  
  1544.         mov     edx, [eax + RING_BUFFER.end_ptr]
  1545.         cmp     [eax + RING_BUFFER.read_ptr], edx
  1546.         jb      @f
  1547.         sub     [eax + RING_BUFFER.read_ptr], SOCKET_MAXDATA
  1548.        @@:
  1549.         ret
  1550.  
  1551.   .error:       ; we could free all available bytes, but that would be stupid, i guess..
  1552.         DEBUGF  1,"SOCKET_ring_free: buffer=%x error!\n", eax
  1553.         add     [eax + RING_BUFFER.size], ecx
  1554.         xor     ecx, ecx
  1555.         ret
  1556.  
  1557.  
  1558. ;-----------------------------------------------------------------
  1559. ;
  1560. ; SOCKET_notify_owner
  1561. ;
  1562. ; notify's the owner of a socket that something happened
  1563. ;
  1564. ;  IN:  eax = socket ptr
  1565. ;  OUT: /
  1566. ;
  1567. ;-----------------------------------------------------------------
  1568. align 4
  1569. SOCKET_notify_owner:
  1570.  
  1571.         DEBUGF  1,"SOCKET_notify_owner: %x\n", eax
  1572.  
  1573.         call    SOCKET_check
  1574.         jz      .error
  1575.  
  1576.         push    eax ecx esi
  1577.  
  1578. ; socket exists, now try to flag an event to the application
  1579.  
  1580.         mov     eax, [eax + SOCKET.PID]
  1581.         test    eax, eax
  1582.         jz      .error2
  1583.         mov     ecx, 1
  1584.         mov     esi, TASK_DATA + TASKDATA.pid
  1585.  
  1586.        .next_pid:
  1587.         cmp     [esi], eax
  1588.         je      .found_pid
  1589.         inc     ecx
  1590.         add     esi, 0x20
  1591.         cmp     ecx, [TASK_COUNT]
  1592.         jbe     .next_pid
  1593.  
  1594. ; PID not found, TODO: close socket!
  1595.  
  1596.         jmp     .error2
  1597.  
  1598.        .found_pid:
  1599.         shl     ecx, 8
  1600.         or      [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK
  1601.         mov     [check_idle_semaphore], 200
  1602.  
  1603.         DEBUGF  1,"SOCKET_notify_owner: succes!\n"
  1604.  
  1605.   .error2:
  1606.         pop     esi ecx eax
  1607.  
  1608.   .error:
  1609.  
  1610.         ret
  1611.  
  1612.  
  1613. ;--------------------------------------------------------------------
  1614. ;
  1615. ; SOCKET_alloc
  1616. ;
  1617. ; Allocate memory for socket data and put new socket into the list
  1618. ; Newly created socket is initialized with calling PID and number and
  1619. ; put into beginning of list (which is a fastest way).
  1620. ;
  1621. ; IN:  /
  1622. ; OUT: eax = 0 on error, socket ptr otherwise
  1623. ;      edi = socket number
  1624. ;       ZF = cleared on error
  1625. ;
  1626. ;--------------------------------------------------------------------
  1627. align 4
  1628. SOCKET_alloc:
  1629.  
  1630.         push    ebx
  1631.  
  1632.         stdcall kernel_alloc, SOCKETBUFFSIZE
  1633.         DEBUGF  1, "SOCKET_alloc: ptr=%x\n", eax
  1634.         or      eax, eax
  1635.         jz      .exit
  1636.  
  1637. ; zero-initialize allocated memory
  1638.         push    eax
  1639.         mov     edi, eax
  1640.         mov     ecx, SOCKETBUFFSIZE / 4
  1641.         xor     eax, eax
  1642.         rep     stosd
  1643.         pop     eax
  1644.  
  1645. ; set send-and receive procedures to return -1
  1646.         mov     [eax + SOCKET.snd_proc], s_error
  1647.         mov     [eax + SOCKET.rcv_proc], s_error
  1648.  
  1649. ; find first free socket number and use it
  1650.         mov     edi, [last_socket_num]
  1651.   .next_socket_number:
  1652.         inc     edi
  1653.         jz      .next_socket_number     ; avoid socket nr 0
  1654.         cmp     edi, -1
  1655.         je      .next_socket_number     ; avoid socket nr -1
  1656.         mov     ebx, net_sockets
  1657.   .next_socket:
  1658.         mov     ebx, [ebx + SOCKET.NextPtr]
  1659.         test    ebx, ebx
  1660.         jz      .last_socket
  1661.  
  1662.         cmp     [ebx + SOCKET.Number], edi
  1663.         jne     .next_socket
  1664.         jmp     .next_socket_number
  1665.  
  1666.   .last_socket:
  1667.         mov     [last_socket_num], edi
  1668.         mov     [eax + SOCKET.Number], edi
  1669.         DEBUGF  1, "SOCKET_alloc: number=%u\n", edi
  1670.  
  1671. ; Fill in PID
  1672.         mov     ebx, [TASK_BASE]
  1673.         mov     ebx, [ebx + TASKDATA.pid]
  1674.         mov     [eax + SOCKET.PID], ebx
  1675.  
  1676. ; init mutex
  1677.         pusha
  1678.         lea     ecx, [eax + SOCKET.mutex]
  1679.         call    mutex_init
  1680.         popa
  1681.  
  1682. ; add socket to the list by re-arranging some pointers
  1683.         mov     ebx, [net_sockets + SOCKET.NextPtr]
  1684.  
  1685.         mov     [eax + SOCKET.PrevPtr], net_sockets
  1686.         mov     [eax + SOCKET.NextPtr], ebx
  1687.  
  1688.         test    ebx, ebx
  1689.         jz      @f
  1690.  
  1691.         pusha
  1692.         lea     ecx, [ebx + SOCKET.mutex]
  1693.         call    mutex_lock
  1694.         popa
  1695.  
  1696.         mov     [ebx + SOCKET.PrevPtr], eax
  1697.  
  1698.         pusha
  1699.         lea     ecx, [ebx + SOCKET.mutex]
  1700.         call    mutex_unlock
  1701.         popa
  1702.        @@:
  1703.  
  1704.         mov     [net_sockets + SOCKET.NextPtr], eax
  1705.         or      eax, eax                ; used to clear zero flag
  1706.   .exit:
  1707.         pop     ebx
  1708.  
  1709.         ret
  1710.  
  1711.  
  1712. ;----------------------------------------------------
  1713. ;
  1714. ; SOCKET_free
  1715. ;
  1716. ; Free socket data memory and remove socket from the list
  1717. ;
  1718. ; IN:  eax = socket ptr
  1719. ; OUT: /
  1720. ;
  1721. ;----------------------------------------------------
  1722. align 4
  1723. SOCKET_free:
  1724.  
  1725.         DEBUGF  1, "SOCKET_free: %x\n", eax
  1726.  
  1727.         call    SOCKET_check
  1728.         jz      .error
  1729.  
  1730.         push    ebx
  1731.  
  1732.         pusha
  1733.         lea     ecx, [eax + SOCKET.mutex]
  1734.         call    mutex_lock
  1735.         popa
  1736.  
  1737.         cmp     [eax + SOCKET.Domain], AF_INET4
  1738.         jnz     .no_tcp
  1739.  
  1740.         cmp     [eax + SOCKET.Protocol], IP_PROTO_TCP
  1741.         jnz     .no_tcp
  1742.  
  1743.         mov     ebx, eax
  1744.         stdcall kernel_free, [ebx + STREAM_SOCKET.rcv.start_ptr]
  1745.         stdcall kernel_free, [ebx + STREAM_SOCKET.snd.start_ptr]
  1746.         mov     eax, ebx
  1747.   .no_tcp:
  1748.  
  1749.         push    eax                             ; this will be passed to kernel_free
  1750.         mov     ebx, [eax + SOCKET.NextPtr]
  1751.         mov     eax, [eax + SOCKET.PrevPtr]
  1752.  
  1753.         DEBUGF  1, "SOCKET_free: linking socket %x to socket %x\n", eax, ebx
  1754.  
  1755.         test    eax, eax
  1756.         jz      @f
  1757.         mov     [eax + SOCKET.NextPtr], ebx
  1758.        @@:
  1759.  
  1760.         test    ebx, ebx
  1761.         jz      @f
  1762.         mov     [ebx + SOCKET.PrevPtr], eax
  1763.        @@:
  1764.  
  1765.         call    kernel_free
  1766.         pop     ebx
  1767.  
  1768.         DEBUGF  1, "SOCKET_free: success!\n"
  1769.  
  1770.   .error:
  1771.         ret
  1772.  
  1773. ;------------------------------------
  1774. ;
  1775. ; SOCKET_fork
  1776. ;
  1777. ; Create a child socket
  1778. ;
  1779. ; IN:  socket nr in ebx
  1780. ; OUT: child socket nr in eax
  1781. ;
  1782. ;-----------------------------------
  1783. align 4
  1784. SOCKET_fork:
  1785.  
  1786.         DEBUGF  1,"SOCKET_fork: %x\n", ebx
  1787.  
  1788. ; Exit if backlog queue is full
  1789.         mov     eax, [ebx + SOCKET_QUEUE_LOCATION + queue.size]
  1790.         cmp     ax, [ebx + SOCKET.backlog]
  1791.         jae     .fail
  1792.  
  1793. ; Allocate new socket
  1794.         push    ebx
  1795.         call    SOCKET_alloc
  1796.         pop     ebx
  1797.         jz      .fail
  1798.  
  1799.         push    eax
  1800.         mov     esi, esp
  1801.         add_to_queue (ebx + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .fail2
  1802.         pop     eax
  1803.  
  1804. ; Copy structure from current socket to new
  1805. ; We start at PID to preserve the socket num, and the 2 pointers at beginning of socket
  1806.         lea     esi, [ebx + SOCKET.PID]
  1807.         lea     edi, [eax + SOCKET.PID]
  1808.         mov     ecx, (SOCKET_QUEUE_LOCATION - SOCKET.PID + 3)/4
  1809.         rep     movsd
  1810.  
  1811.         and     [eax + SOCKET.options], not SO_ACCEPTCON
  1812.  
  1813.         ret
  1814.  
  1815.   .fail2:
  1816.         add     esp, 4+4+4
  1817.   .fail:
  1818.         DEBUGF  1,"SOCKET_fork: failed\n"
  1819.         xor     eax, eax
  1820.         ret
  1821.  
  1822.  
  1823. ;---------------------------------------------------
  1824. ;
  1825. ; SOCKET_num_to_ptr
  1826. ;
  1827. ; Get socket structure address by its number
  1828. ;
  1829. ; IN:  ecx = socket number
  1830. ; OUT: eax = 0 on error, socket ptr otherwise
  1831. ;       ZF = set on error
  1832. ;
  1833. ;---------------------------------------------------
  1834. align 4
  1835. SOCKET_num_to_ptr:
  1836.  
  1837.         DEBUGF  1,"SOCKET_num_to_ptr: num=%u ", ecx
  1838.  
  1839.         mov     eax, net_sockets
  1840.  
  1841.   .next_socket:
  1842.         mov     eax, [eax + SOCKET.NextPtr]
  1843.         or      eax, eax
  1844.         jz      .error
  1845.         cmp     [eax + SOCKET.Number], ecx
  1846.         jne     .next_socket
  1847.  
  1848.         test    eax, eax
  1849.  
  1850.         DEBUGF  1,"ptr=%x\n", eax
  1851.         ret
  1852.  
  1853.   .error:
  1854.         DEBUGF  1,"not found\n", eax
  1855.         ret
  1856.  
  1857.  
  1858. ;---------------------------------------------------
  1859. ;
  1860. ; SOCKET_ptr_to_num
  1861. ;
  1862. ; Get socket number by its address
  1863. ;
  1864. ; IN:  eax = socket ptr
  1865. ; OUT: eax = 0 on error, socket num otherwise
  1866. ;       ZF = set on error
  1867. ;
  1868. ;---------------------------------------------------
  1869. align 4
  1870. SOCKET_ptr_to_num:
  1871.  
  1872.         DEBUGF  1,"SOCKET_ptr_to_num: ptr=%x ", eax
  1873.  
  1874.         call    SOCKET_check
  1875.         jz      .error
  1876.  
  1877.         mov     eax, [eax + SOCKET.Number]
  1878.  
  1879.         DEBUGF  1,"num=%u\n", eax
  1880.         ret
  1881.  
  1882.   .error:
  1883.         DEBUGF  1,"not found\n", eax
  1884.         ret
  1885.  
  1886.  
  1887. ;---------------------------------------------------
  1888. ;
  1889. ; SOCKET_check
  1890. ;
  1891. ; checks if the given value is really a socket ptr
  1892. ;
  1893. ; IN:  eax = socket ptr
  1894. ; OUT: eax = 0 on error, unchanged otherwise
  1895. ;       ZF = set on error
  1896. ;
  1897. ;---------------------------------------------------
  1898. align 4
  1899. SOCKET_check:
  1900.  
  1901.         DEBUGF  1,"SOCKET_check: %x\n", eax
  1902.  
  1903.         push    ebx
  1904.         mov     ebx, net_sockets
  1905.  
  1906.   .next_socket:
  1907.         mov     ebx, [ebx + SOCKET.NextPtr]
  1908.         or      ebx, ebx
  1909.         jz      .done
  1910.         cmp     ebx, eax
  1911.         jnz     .next_socket
  1912.  
  1913.   .done:
  1914.         mov     eax, ebx
  1915.         test    eax, eax
  1916.         pop     ebx
  1917.  
  1918.         ret
  1919.  
  1920.  
  1921.  
  1922. ;---------------------------------------------------
  1923. ;
  1924. ; SOCKET_check_owner
  1925. ;
  1926. ; checks if the caller application owns the socket
  1927. ;
  1928. ; IN:  eax = socket ptr
  1929. ; OUT:  ZF = true/false
  1930. ;
  1931. ;---------------------------------------------------
  1932. align 4
  1933. SOCKET_check_owner:
  1934.  
  1935.         DEBUGF  1,"SOCKET_check_owner: %x\n", eax
  1936.  
  1937.         push    ebx
  1938.         mov     ebx, [TASK_BASE]
  1939.         mov     ebx, [ecx + TASKDATA.pid]
  1940.         cmp     [eax + SOCKET.PID], ebx
  1941.         pop      ebx
  1942.  
  1943.         ret
  1944.  
  1945.  
  1946.  
  1947.  
  1948. ;------------------------------------------------------
  1949. ;
  1950. ; SOCKET_process_end
  1951. ;
  1952. ; Kernel calls this function when a certain process ends
  1953. ; This function will check if the process had any open sockets
  1954. ; And update them accordingly
  1955. ;
  1956. ; IN:  edx = pid
  1957. ; OUT: /
  1958. ;
  1959. ;------------------------------------------------------
  1960. align 4
  1961. SOCKET_process_end:
  1962.  
  1963.         DEBUGF  1,"SOCKET_process_end: %x\n", edx
  1964.  
  1965.         push    ebx
  1966.         mov     ebx, net_sockets
  1967.  
  1968.   .next_socket:
  1969.         mov     ebx, [ebx + SOCKET.NextPtr]
  1970.   .test_socket:
  1971.         test    ebx, ebx
  1972.         jz      .done
  1973.  
  1974.         cmp     [ebx + SOCKET.PID], edx
  1975.         jne     .next_socket
  1976.  
  1977.         DEBUGF  1,"SOCKET_process_end: killing socket %x\n", ebx
  1978.  
  1979.         mov     [ebx + SOCKET.PID], 0
  1980.  
  1981.         cmp     [ebx + SOCKET.Protocol], IP_PROTO_TCP
  1982.         je      .tcp
  1983.  
  1984. ; The socket is stateless, just kill it right away!
  1985.  
  1986.         mov     eax, ebx
  1987.         mov     ebx, [ebx + SOCKET.NextPtr]
  1988.         call    SOCKET_free
  1989.         jmp     .test_socket
  1990.  
  1991.   .tcp:
  1992.         push    [ebx + SOCKET.NextPtr]
  1993.         mov     eax, ebx
  1994.         call    TCP_disconnect
  1995.         pop     ebx
  1996.         jmp     .test_socket
  1997.  
  1998.   .done:
  1999.         pop     ebx
  2000.  
  2001.         ret
  2002.  
  2003.  
  2004.  
  2005.  
  2006. ;-----------------------------------------------------------------
  2007. ;
  2008. ; SOCKET_is_connecting
  2009. ;
  2010. ;  IN:  eax = socket ptr
  2011. ;  OUT: /
  2012. ;
  2013. ;-----------------------------------------------------------------
  2014.  
  2015. align 4
  2016. SOCKET_is_connecting:
  2017.  
  2018.         DEBUGF  1,"SOCKET_is_connecting: %x\n", eax
  2019.  
  2020.         and     [eax + SOCKET.options], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING)
  2021.         or      [eax + SOCKET.options], SS_ISCONNECTING
  2022.  
  2023.         jmp     SOCKET_notify_owner
  2024.  
  2025.  
  2026.  
  2027. ;-----------------------------------------------------------------
  2028. ;
  2029. ; SOCKET_is_connected
  2030. ;
  2031. ;  IN:  eax = socket ptr
  2032. ;  OUT: /
  2033. ;
  2034. ;-----------------------------------------------------------------
  2035.  
  2036. align 4
  2037. SOCKET_is_connected:
  2038.  
  2039.         DEBUGF  1,"SOCKET_is_connected: %x\n", eax
  2040.  
  2041.         and     [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING)
  2042.         or      [eax + SOCKET.options], SS_ISCONNECTED
  2043.  
  2044.         jmp     SOCKET_notify_owner
  2045.  
  2046.  
  2047.  
  2048.  
  2049. ;-----------------------------------------------------------------
  2050. ;
  2051. ; SOCKET_is_disconnecting
  2052. ;
  2053. ;  IN:  eax = socket ptr
  2054. ;  OUT: /
  2055. ;
  2056. ;-----------------------------------------------------------------
  2057.  
  2058. align 4
  2059. SOCKET_is_disconnecting:
  2060.  
  2061.         DEBUGF  1,"SOCKET_is_disconnecting: %x\n", eax
  2062.  
  2063.         and     [eax + SOCKET.options], not (SS_ISCONNECTING)
  2064.         or      [eax + SOCKET.options], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE
  2065.  
  2066.         jmp     SOCKET_notify_owner
  2067.  
  2068.  
  2069.  
  2070. ;-----------------------------------------------------------------
  2071. ;
  2072. ; SOCKET_is_disconnected
  2073. ;
  2074. ;  IN:  eax = socket ptr
  2075. ;  OUT: /
  2076. ;
  2077. ;-----------------------------------------------------------------
  2078.  
  2079. align 4
  2080. SOCKET_is_disconnected:
  2081.  
  2082.         DEBUGF  1,"SOCKET_is_disconnected: %x\n", eax
  2083.  
  2084.         and     [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING)
  2085.         or      [eax + SOCKET.options], SS_CANTRCVMORE + SS_CANTSENDMORE
  2086.  
  2087.         jmp     SOCKET_notify_owner
  2088.  
  2089.  
  2090. ;-----------------------------------------------------------------
  2091. ;
  2092. ; SOCKET_cant_recv_more
  2093. ;
  2094. ;  IN:  eax = socket ptr
  2095. ;  OUT: /
  2096. ;
  2097. ;-----------------------------------------------------------------
  2098.  
  2099. align 4
  2100. SOCKET_cant_recv_more:
  2101.  
  2102.         DEBUGF  1,"SOCKET_cant_recv_more: %x\n", eax
  2103.  
  2104.         or      [eax + SOCKET.options], SS_CANTRCVMORE
  2105.  
  2106.         ret
  2107.  
  2108.  
  2109.  
  2110. ;-----------------------------------------------------------------
  2111. ;
  2112. ; SOCKET_cant_send_more
  2113. ;
  2114. ;  IN:  eax = socket ptr
  2115. ;  OUT: /
  2116. ;
  2117. ;-----------------------------------------------------------------
  2118.  
  2119. align 4
  2120. SOCKET_cant_send_more:
  2121.  
  2122.         DEBUGF  1,"SOCKET_cant_send_more: %x\n", eax
  2123.  
  2124.         or      [eax + SOCKET.options], SS_CANTSENDMORE
  2125.  
  2126.         ret