/kernel/trunk/network/socket.inc |
---|
302,7 → 302,7 |
; 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 |
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 |
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 |
mov ebx, esi ; bufferlength |
.loop: |
get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, .block ; destroys esi and ecx |
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 |
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 |
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,62 → 960,42 |
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 |
;----------------------------------------------------------------- |
; |
; SOCKET_send |
1251,9 → 1246,6 |
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 |
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 |
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 |
/kernel/trunk/network/stack.inc |
---|
81,7 → 81,6 |
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 |
/programs/develop/libraries/network/network.inc |
---|
File deleted |
/programs/develop/libraries/network/network.asm |
---|
7,7 → 7,7 |
include '../../../macros.inc' |
purge section,mov,add,sub |
include 'network.inc' |
include '../../../network.inc' |
section '.flat' code readable align 16 |
761,7 → 761,7 |
; 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 |
/programs/network/downloader/downloader.asm |
---|
187,6 → 187,7 |
jmp still |
exit: |
DEBUGF 1, "Exiting\n" |
or eax, -1 ; close this program |
mcall |
208,6 → 209,10 |
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 |
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,7 → 359,7 |
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 |
365,8 → 366,10 |
.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... |
/programs/network/ftpc/ftpc.asm |
---|
161,7 → 161,7 |
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 |
/programs/network/ftpc/servercommands.inc |
---|
80,7 → 80,7 |
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 |
/programs/network/ftpd/ftpd.asm |
---|
270,7 → 270,7 |
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 |
/programs/network/ircc/socket.inc |
---|
205,11 → 205,11 |
; 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 |
/programs/network/synergyc/synergyc.asm |
---|
286,8 → 286,6 |
wait_for_data: |
mcall 10 ; wait for data |
mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, 0 |
cmp eax, -1 |
je wait_for_data |
/programs/network/tcpserv/tcpserv.asm |
---|
91,8 → 91,6 |
mcall send, [socketnum2], hello, hello.length |
.loop: |
mcall 10 |
mcall recv, [socketnum2], buffer, buffer.length, 0 |
cmp eax, -1 |
je .loop |
/programs/network/telnet/telnet.asm |
---|
171,25 → 171,15 |
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 |
.print: |
cmp esi, edi |
jae .check_for_data |
jae mainloop |
push esi |
call [con_write_asciiz] |
/programs/network/tftpc/tftpc.asm |
---|
308,7 → 308,7 |
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 |
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 |
/programs/network/vncc/thread.inc |
---|
3,7 → 3,7 |
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 |
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 |
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 |
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 |
wait_for_data: |
mcall 23, 500 |
mcall recv, [socketnum], receive_buffer, 4096, 0 |
cmp eax, -1 |
je wait_for_data |
/programs/network/zeroconf/zeroconf.asm |
---|
295,7 → 295,7 |
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" |
/programs/network.inc |
---|
42,6 → 42,10 |
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 |