Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 1256 → Rev 1257

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