use blocking sockets by default.

git-svn-id: svn://kolibrios.org@3704 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-06-25 20:02:56 +00:00
parent c9f7535c89
commit 97c13d77de
16 changed files with 158 additions and 291 deletions

View File

@ -302,7 +302,7 @@ SOCKET_open:
; push edx
; and edx, SO_NONBLOCK
or [eax + SOCKET.options], SO_NONBLOCK ;edx ; HACK: make all sockets non-blocking untill API and applications are fixed
; or [eax + SOCKET.options], SO_NONBLOCK ;edx ; HACK: make all sockets non-blocking untill API and applications are fixed
; pop edx
; and edx, not SO_NONBLOCK
@ -611,7 +611,7 @@ align 4
jz .loop
mov dword[esp+20], EWOULDBLOCK
mov dword[esp+32], 0 ; Should be -1? or not?
mov dword[esp+32], -1
ret
.loop:
@ -860,32 +860,50 @@ SOCKET_receive:
call SOCKET_num_to_ptr
jz .invalid
.loop:
push edi
call [eax + SOCKET.rcv_proc]
pop edi
cmp ebx, EWOULDBLOCK
jne .return
test edi, MSG_DONTWAIT
jnz .return_err
; test [eax + SOCKET.options], SO_NONBLOCK
; jnz .return_err
call SOCKET_block
jmp .loop
.invalid:
push EINVAL
pop ebx
.return_err:
mov eax, -1
.return:
mov [esp+20], ebx
mov [esp+32], eax
ret
.invalid:
mov dword[esp+20], EINVAL
mov dword[esp+32], -1
ret
align 4
SOCKET_receive_dgram:
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_receive: DGRAM\n"
mov ebx, esi
mov edi, edx ; addr to buffer
.loop:
get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, .block ; destroys esi and ecx
mov ebx, esi ; bufferlength
get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, .wouldblock ; sets esi only on success.
mov ecx, [esi + socket_queue_entry.data_size]
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_receive: %u bytes data\n", ecx
cmp ecx, ebx
cmp ecx, ebx ; If data segment does not fit in applications buffer, abort
ja .too_small
push ecx
@ -893,7 +911,8 @@ SOCKET_receive_dgram:
mov esi, [esi + socket_queue_entry.data_ptr]
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_receive: Source buffer=%x real addr=%x\n", [esp], esi
; copy the data
; copy the data from kernel buffer to application buffer
mov edi, edx ; bufferaddr
shr ecx, 1
jnc .nb
movsb
@ -907,28 +926,24 @@ SOCKET_receive_dgram:
rep movsd
.nd:
call kernel_free ; remove the packet
pop eax
call kernel_free ; free kernel buffer
pop eax ; return number of bytes copied to application
xor ebx, ebx
ret
.too_small:
mov eax, -1
mov ebx, EMSGSIZE
push EMSGSIZE
pop ebx
ret
.block:
test [eax + SOCKET.options], SO_NONBLOCK
jnz .wouldblock
call SOCKET_block
jmp .loop
.wouldblock:
mov eax, -1
mov ebx, EWOULDBLOCK
push EWOULDBLOCK
pop ebx
ret
align 4
SOCKET_receive_local:
@ -945,61 +960,41 @@ SOCKET_receive_local:
mov [eax + SOCKET.rcv_proc], SOCKET_receive_stream
; ... continue to SOCKET_receive_stream
align 4
SOCKET_receive_stream:
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_receive: STREAM\n"
mov ebx, edi
cmp [eax + STREAM_SOCKET.rcv + RING_BUFFER.size], 0
je .wouldblock
test edi, MSG_PEEK
jnz .peek
mov ecx, esi
mov edi, edx
xor edx, edx
test ebx, MSG_DONTWAIT
jnz .dontwait
.loop:
cmp [eax + STREAM_SOCKET.rcv + RING_BUFFER.size], 0
je .block
.dontwait:
test ebx, MSG_PEEK
jnz .peek
add eax, STREAM_SOCKET.rcv
call SOCKET_ring_read
call SOCKET_ring_free
call SOCKET_ring_read ; copy data from kernel buffer to application buffer
call SOCKET_ring_free ; free read memory
mov eax, ecx ; return number of bytes copied
xor ebx, ebx ; errorcode = 0 (no error)
ret
.wouldblock:
push EWOULDBLOCK
pop ebx
ret
.peek:
mov eax, [eax + STREAM_SOCKET.rcv + RING_BUFFER.size]
xor ebx, ebx
ret
.block:
test [eax + SOCKET.options], SO_NONBLOCK
jnz .wouldblock
call SOCKET_block
jmp .loop
.return0:
test [eax + SOCKET.options], SS_CANTRCVMORE
jz .ok
xor eax, eax
dec eax
ret
.ok:
xor eax, eax
ret
.wouldblock:
mov eax, -1
mov ebx, EWOULDBLOCK
ret
;-----------------------------------------------------------------
;
@ -1251,9 +1246,6 @@ SOCKET_set_opt:
cmp dword [edx+4], SO_BINDTODEVICE
je .bind
cmp dword [edx+4], SO_BLOCK
je .block
.invalid:
mov dword[esp+32], -1
mov dword[esp+20], EINVAL
@ -1283,21 +1275,6 @@ SOCKET_set_opt:
mov dword[esp+32], 0 ; success!
ret
.block:
cmp dword[edx+8], 0
je .unblock
and [eax + SOCKET.options], not SO_NONBLOCK
mov dword[esp+32], 0 ; success!
ret
.unblock:
or [eax + SOCKET.options], SO_NONBLOCK
mov dword[esp+32], 0 ; success!
ret
.already:
mov dword[esp+20], EALREADY
mov dword[esp+32], -1
@ -1886,8 +1863,8 @@ SOCKET_notify:
test [eax + SOCKET.state], SS_BLOCKED
jnz .unblock
test [eax + SOCKET.options], SO_NONBLOCK
jz .error
; test [eax + SOCKET.options], SO_NONBLOCK
; jz .error
push eax ecx esi

View File

@ -81,7 +81,6 @@ SO_REUSEPORT = 1 shl 7
SO_USELOOPBACK = 1 shl 8
SO_BINDTODEVICE = 1 shl 9
SO_BLOCK = 1 shl 10 ; TO BE REMOVED
SO_NONBLOCK = 1 shl 31
; Socket flags for user calls

View File

@ -7,7 +7,7 @@ include '../../../proc32.inc'
include '../../../macros.inc'
purge section,mov,add,sub
include 'network.inc'
include '../../../network.inc'
section '.flat' code readable align 16
@ -761,7 +761,7 @@ end virtual
; 2. Read UDP datagram.
mov ecx, [edi+__gai_reqdata.socketnum]
push edi
mcall 75, 7, , , 512, 0
mcall 75, 7, , , 512, MSG_DONTWAIT
pop edi
; 3. Ignore events for other socketnums (return if no data read)
test eax, eax

View File

@ -1,94 +0,0 @@
; Socket types
SOCK_STREAM = 1
SOCK_DGRAM = 2
SOCK_RAW = 3
; Socket options
SO_NONBLOCK = 1 shl 31
; IP protocols
IPPROTO_IP = 0
IPPROTO_ICMP = 1
IPPROTO_TCP = 6
IPPROTO_UDP = 17
; Address families
AF_UNSPEC = 0
AF_LOCAL = 1
AF_INET4 = 2 ; IPv4
AF_INET6 = 28 ; IPv6 (not supported yet)
PF_UNSPEC = AF_UNSPEC
PF_LOCAL = AF_LOCAL
PF_INET4 = AF_INET4
PF_INET6 = AF_INET6
; Flags for addrinfo
AI_PASSIVE = 1
AI_CANONNAME = 2
AI_NUMERICHOST = 4
AI_NUMERICSERV = 8
AI_ADDRCONFIG = 0x400
; internal definition
AI_SUPPORTED = 0x40F
; for system function 76
API_ETH = 0 shl 16
API_IPv4 = 1 shl 16
API_ICMP = 2 shl 16
API_UDP = 3 shl 16
API_TCP = 4 shl 16
API_ARP = 5 shl 16
API_PPPOE = 6 shl 16
struct sockaddr_in
sin_family dw ? ; sa_family_t
sin_port dw ? ; in_port_t
sin_addr dd ? ; struct in_addr
sin_zero rb 8 ; zero
ends
struct addrinfo
ai_flags dd ? ; bitmask of AI_*
ai_family dd ? ; PF_*
ai_socktype dd ? ; SOCK_*
ai_protocol dd ? ; 0 or IPPROTO_*
ai_addrlen dd ? ; length of ai_addr
ai_canonname dd ? ; char*
ai_addr dd ? ; struct sockaddr*
ai_next dd ? ; struct addrinfo*
ends
EAI_ADDRFAMILY = 1
EAI_AGAIN = 2
EAI_BADFLAGS = 3
EAI_FAIL = 4
EAI_FAMILY = 5
EAI_MEMORY = 6
EAI_NONAME = 8
EAI_SERVICE = 9
EAI_SOCKTYPE = 10
EAI_BADHINTS = 12
EAI_PROTOCOL = 13
EAI_OVERFLOW = 14
socket fix 75, 0
close fix 75, 1
bind fix 75, 2
listen fix 75, 3
connect fix 75, 4
accept fix 75, 5
send fix 75, 6
recv fix 75, 7
setsockopt fix 75, 8
getsockopt fix 75, 9
socketpair fix 75, 10
struct ARP_entry
IP dd ?
MAC dp ?
status dw ?
TTL dw ?
ends

View File

@ -42,6 +42,10 @@ API_TCP = 4 shl 16
API_ARP = 5 shl 16
API_PPPOE = 6 shl 16
; Socket flags for user calls
MSG_PEEK = 0x02
MSG_DONTWAIT = 0x40
struct sockaddr_in
sin_family dw ? ; sa_family_t
sin_port dw ? ; in_port_t

View File

@ -187,6 +187,7 @@ mouse:
jmp still
exit:
DEBUGF 1, "Exiting\n"
or eax, -1 ; close this program
mcall
@ -208,6 +209,10 @@ save:
cmp byte[params], 0
jne exit
mov ecx, [sc.work_text]
or ecx, 0x80000000
mcall 4, <10, 93>, , download_complete
ret
save_in_shared:
@ -249,10 +254,6 @@ save_to_file:
DEBUGF 2, "Saving to file\n"
mcall 70, fileinfo
mov ecx, [sc.work_text]
or ecx, 0x80000000
mcall 4, <10, 93>, , download_complete
ret
@ -358,15 +359,17 @@ read_incoming_data:
DEBUGF 1, "Reading incoming data\n"
mcall 40, EVM_STACK ; we only want stack events now
mcall 40, EVM_STACK + EVM_BUTTON
mov eax, [buf_ptr]
mov [pos], eax
.read:
mcall 23, 100 ; 1 second timeout
cmp eax, EV_BUTTON
je exit
.read_dontwait:
mcall recv, [socketnum], [pos], BUFFERSIZE, 0
mcall recv, [socketnum], [pos], BUFFERSIZE, MSG_DONTWAIT
inc eax ; -1 = error (socket closed?)
jz .no_more_data
dec eax ; 0 bytes...

View File

@ -161,7 +161,7 @@ wait_for_serverdata:
jnz exit
; receive socket data
mcall recv, [socketnum], [offset], BUFFERSIZE, 0
mcall recv, [socketnum], [offset], BUFFERSIZE, MSG_DONTWAIT
inc eax
jz wait_for_serverdata
dec eax

View File

@ -80,7 +80,7 @@ pasv_ok:
data_ok:
mcall recv, [datasocket], buffer_ptr, BUFFERSIZE, 0 ; fixme: use other buffer
mcall recv, [datasocket], buffer_ptr, BUFFERSIZE, MSG_DONTWAIT ; fixme: use other buffer
inc eax
jz .fail
dec eax

View File

@ -270,7 +270,7 @@ threadloop:
mov ecx, [ebp + thread_data.socketnum]
mov edx, [ebp + thread_data.buffer_ptr]
mov esi, sizeof.thread_data.buffer ;;; FIXME
xor edi, edi
mov edi, MSG_DONTWAIT
mcall recv
inc eax ; error? (-1)
jz threadloop

View File

@ -205,11 +205,11 @@ read_incoming_data:
; TODO: read more data if we receive one full packet
.nextpacket:
mcall recv, [socketnum], packetbuf, 1024, 0 ; read a packet
mcall recv, [socketnum], packetbuf, 1024, MSG_DONTWAIT ; read a packet
inc eax ; check if we got one
jz .done
dec eax
jz .done
jz .done ; TODO: check for errors!
; ok we have data, now feed it to the recoder

View File

@ -286,8 +286,6 @@ exit:
wait_for_data:
mcall 10 ; wait for data
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, 0
cmp eax, -1
je wait_for_data

View File

@ -91,8 +91,6 @@ start:
mcall send, [socketnum2], hello, hello.length
.loop:
mcall 10
mcall recv, [socketnum2], buffer, buffer.length, 0
cmp eax, -1
je .loop

View File

@ -171,25 +171,15 @@ resolve:
mcall 18, 3
mainloop:
DEBUGF 1, 'TELNET: Waiting for events\n'
mcall 10
DEBUGF 1, 'TELNET: EVENT %x !\n', eax
call [con_get_flags]
test eax, 0x200 ; con window closed?
jnz exit
.check_for_data:
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, 0
cmp eax, -1
jne .parse_data
cmp ebx, 6 ; EWOULDBLOCK
je mainloop
jmp closed
je closed
.parse_data:
DEBUGF 1, 'TELNET: got %u bytes of data !\n', eax
mov esi, buffer_ptr
@ -217,7 +207,7 @@ mainloop:
.print:
cmp esi, edi
jae .check_for_data
jae mainloop
push esi
call [con_write_asciiz]

View File

@ -308,7 +308,7 @@ receive_data_loop:
jz .key
mcall recv, [socketnum], buffer, buffer_len, 0 ; receive data
mcall recv, [socketnum], buffer, buffer_len, MSG_DONTWAIT ; receive data
cmp word[buffer], opcode_data
jne .error
@ -415,7 +415,7 @@ send_:
dec eax
jz .key
mcall recv, [socketnum], buffer, buffer_len, 0 ; receive ack
mcall recv, [socketnum], buffer, buffer_len, MSG_DONTWAIT ; receive ack
cmp word[buffer], opcode_ack
jne .exit

View File

@ -3,7 +3,7 @@ thread_start:
DEBUGF 1, 'I am the thread!\n'
mcall 40, 1 shl 7
mcall 40, 0
; resolve name
push esp ; reserve stack place
@ -55,8 +55,6 @@ no_security:
mcall send, [socketnum], shared, 1, 0
DEBUGF 1, 'Sending handshake: shared session?\n'
mcall 23, 100*TIMEOUT
call wait_for_data ; now the server should send init message
DEBUGF 1, 'Serverinit: bpp: %u depth: %u bigendian: %u truecolor: %u\n', \
@ -85,8 +83,6 @@ request_rfb:
mcall send, [socketnum], fbur, 10, 0
thread_loop:
mcall 23, 100
call read_data ; Read the data into the buffer
; cmp eax, 2
@ -206,10 +202,8 @@ servercuttext:
read_data:
mov [datapointer], receive_buffer
.loop:
mcall 23, 100*TIMEOUT
mcall recv, [socketnum], [datapointer], 4096, 0
cmp eax, -1
je .done
@ -227,8 +221,6 @@ read_data:
wait_for_data:
mcall 23, 500
mcall recv, [socketnum], receive_buffer, 4096, 0
cmp eax, -1
je wait_for_data

View File

@ -295,7 +295,7 @@ send_dhcpmsg:
mcall 23, TIMEOUT*100 ; wait for data
read_data: ; we have data - this will be the response
mcall 75, 7, [socketNum], [dhcpMsg], BUFFER, 0 ; read data from socket
mcall 75, 7, [socketNum], [dhcpMsg], BUFFER, MSG_DONTWAIT ; read data from socket
cmp eax, -1
jne @f
DEBUGF 1,"No answer from DHCP server\n"