Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 1257 → Rev 1256

/kernel/branches/net/network/socket.inc
97,7 → 97,6
MAX_backlog equ 20 ; backlog for stream sockets
SOCKETBUFFSIZE equ 4096 ; in bytes
SOCKET_QUEUE_SIZE equ 10 ; maximum number ofincoming packets queued for 1 socket
SOCKET_QUEUE_LOCATION equ 2048 ; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start
 
uglobal
net_sockets rd 2
106,7 → 105,7
endg
 
 
;-----------------------------------------------------------------
;-----------------------------------------------
;
; SOCKET_init
;
115,7 → 114,8
; IN: /
; OUT: /
;
;-----------------------------------------------------------------
;-----------------------------------------------
 
align 4
socket_init:
 
128,11 → 128,12
ret
 
 
;-----------------------------------------------------------------
;-----------------------------------------------
;
; Socket API (function 74)
;
;-----------------------------------------------------------------
;-----------------------------------------------
 
align 4
sys_socket:
and ebx, 0x000000FF ; should i remove this line ?
160,7 → 161,7
ret
 
 
;-----------------------------------------------------------------
;-----------------------------------------------
;
; SOCKET_open
;
170,7 → 171,7
; protocol in esi
; OUT: eax is socket num, -1 on error
;
;-----------------------------------------------------------------
;-----------------------------------------------
align 4
socket_open:
 
187,7 → 188,7
stdcall net_socket_addr_to_num, eax
DEBUGF 1,", socketnumber: %u\n", eax
 
; TODO: if it is a tcp socket, set state to TCB_CLOSED
; TODO: if it is txcp socket, set state to TCB_CLOSED
 
mov [esp+32], eax
 
195,7 → 196,12
 
 
 
;-----------------------------------------------------------------
 
 
 
 
 
;-----------------------------------------------
;
; SOCKET_bind
;
204,7 → 210,7
; length of that struct in esi
; OUT: 0 on success
;
;-----------------------------------------------------------------
;-----------------------------------------------
align 4
socket_bind:
 
272,7 → 278,7
 
 
 
;-----------------------------------------------------------------
;-----------------------------------------------
;
; SOCKET_connect
;
282,7 → 288,7
; length of that struct in esi
; OUT: 0 on success
;
;-----------------------------------------------------------------
;-----------------------------------------------
align 4
socket_connect:
 
369,7 → 375,9
ret
 
 
;-----------------------------------------------------------------
 
 
;-----------------------------------------------
;
; SOCKET_listen
;
378,7 → 386,7
; backlog in edx
; OUT: eax is socket num, -1 on error
;
;-----------------------------------------------------------------
;-----------------------------------------------
align 4
socket_listen:
 
406,7 → 414,11
ret
 
 
;-----------------------------------------------------------------
 
 
 
 
;-----------------------------------------------
;
; SOCKET_accept
;
416,7 → 428,7
; addrlen in esi
; OUT: eax is socket num, -1 on error
;
;-----------------------------------------------------------------
;-----------------------------------------------
align 4
socket_accept:
 
457,7 → 469,7
jmp s_error
 
 
;-----------------------------------------------------------------
;-----------------------------------------------
;
; SOCKET_close
;
465,7 → 477,7
; IN: socket number in ecx
; OUT: eax is socket num, -1 on error
;
;-----------------------------------------------------------------
;-----------------------------------------------
align 4
socket_close:
 
547,7 → 559,7
 
 
 
;-----------------------------------------------------------------
;-----------------------------------------------
;
; SOCKET_receive
;
558,7 → 570,7
; flags in edi
; OUT: eax is number of bytes copied, -1 on error
;
;-----------------------------------------------------------------
;-----------------------------------------------
align 4
socket_recv:
 
570,7 → 582,7
 
DEBUGF 1,"Socket pointer: %x\n", eax
 
get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, socket_queue_entry.size, s_error
get_from_queue (eax + 2048), SOCKET_QUEUE_SIZE, 4*3, s_error
 
mov edi, edx
mov ecx, [esi + socket_queue_entry.data_size]
603,7 → 615,7
ret
 
 
;-----------------------------------------------------------------
;-----------------------------------------------
;
; SOCKET_send
;
614,7 → 626,8
; flags in edi
; OUT: -1 on error
;
;-----------------------------------------------------------------
;-----------------------------------------------
 
align 4
socket_send:
 
732,9 → 745,9
mov [esp+32], eax
ret
 
;-----------------------------------------------------------------
;-----------------------------------------------
;
; SOCKET_get_options
; SOCKET_send
;
;
; IN: socket number in ecx
745,10 → 758,8
; At moment, uses only pseudo-optname -2 for get last_ack_number for TCP.
; TODO: find best way to notify that send()'ed data were acknowledged
;
;-----------------------------------------------------------------
align 4
;-----------------------------------------------
socket_get_opt:
 
cmp dword [edx], IP_PROTO_TCP
jnz .unknown
cmp dword [edx+4], -2
769,15 → 780,15
jz @f
mov [eax], ecx
@@:
mov dword [esp+32], 0
xor eax, eax
ret
.fail:
.unknown:
mov dword [esp+32], -1
or eax, -1
ret
 
 
;-----------------------------------------------------------------
;-----------------------------------------------
;
; SOCKET_find_free_port (local port)
;
786,7 → 797,7
; IN: type in ecx (TCP/UDP)
; OUT: bx = 0 on error, portnumber otherwise
;
;-----------------------------------------------------------------
;-----------------------------------------------
align 4
socket_find_port:
 
837,9 → 848,7
rol bx, 8
ret
 
 
 
;-----------------------------------------------------------------
;-----------------------------------------------
;
; SOCKET_check_port (local port)
;
849,7 → 858,7
; port to check in bx
; OUT: bx = 0 on error, unchanged otherwise
;
;-----------------------------------------------------------------
;-----------------------------------------------
align 4
socket_check_port:
mov esi, net_sockets
871,8 → 880,7
ret
 
 
 
;-----------------------------------------------------------------
;-----------------------------------------------
;
; SOCKET_internal_receiver
;
887,7 → 895,7
;
; OUT: xxx
;
;-----------------------------------------------------------------
;-----------------------------------------------
align 4
socket_internal_receiver:
 
897,9 → 905,9
push ecx ; size
push esi ; data_ptr
mov esi, esp
add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, socket_queue_entry.size, notify_network_event.full
add_to_queue (eax + 2048), SOCKET_QUEUE_SIZE, 3*4, notify_network_event.full
DEBUGF 1,"Queued packet successfully\n"
add esp, socket_queue_entry.size
add esp, 4*3
 
mov [eax + SOCKET_head.lock], 0
 
956,7 → 964,7
rep stosd
pop eax
 
init_queue (eax + SOCKET_QUEUE_LOCATION)
init_queue (eax + 2048)
 
; add socket to the list by changing pointers
mov ebx, net_sockets