forked from KolibriOS/kolibrios
separate thread and process ID's for sockets.
git-svn-id: svn://kolibrios.org@3264 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
75968b0534
commit
6b57089391
@ -26,7 +26,8 @@ struct SOCKET
|
|||||||
|
|
||||||
mutex MUTEX
|
mutex MUTEX
|
||||||
|
|
||||||
PID dd ? ; application process id
|
PID dd ? ; process ID
|
||||||
|
TID dd ? ; thread ID
|
||||||
Domain dd ? ; INET/LOCAL/..
|
Domain dd ? ; INET/LOCAL/..
|
||||||
Type dd ? ; RAW/STREAM/DGRAP
|
Type dd ? ; RAW/STREAM/DGRAP
|
||||||
Protocol dd ? ; ICMP/IPv4/ARP/TCP/UDP
|
Protocol dd ? ; ICMP/IPv4/ARP/TCP/UDP
|
||||||
@ -682,10 +683,10 @@ SOCKET_accept:
|
|||||||
; Ok, we got a socket ptr
|
; Ok, we got a socket ptr
|
||||||
mov eax, [esi]
|
mov eax, [esi]
|
||||||
|
|
||||||
; Change PID to that of the current process
|
; Change thread ID to that of the current thread
|
||||||
mov ebx, [TASK_BASE]
|
mov ebx, [TASK_BASE]
|
||||||
mov ebx, [ebx + TASKDATA.pid]
|
mov ebx, [ebx + TASKDATA.pid]
|
||||||
mov [eax + SOCKET.PID], ebx
|
mov [eax + SOCKET.TID], ebx
|
||||||
|
|
||||||
; Convert it to a socket number
|
; Convert it to a socket number
|
||||||
call SOCKET_ptr_to_num
|
call SOCKET_ptr_to_num
|
||||||
@ -717,22 +718,18 @@ SOCKET_close:
|
|||||||
call SOCKET_num_to_ptr
|
call SOCKET_num_to_ptr
|
||||||
jz s_error
|
jz s_error
|
||||||
|
|
||||||
|
mov dword [esp+32], 0 ; The socket exists, so we will succeed in closing it.
|
||||||
|
|
||||||
|
.socket:
|
||||||
cmp [eax + SOCKET.Domain], AF_INET4
|
cmp [eax + SOCKET.Domain], AF_INET4
|
||||||
jne s_error
|
jne .free
|
||||||
|
|
||||||
cmp [eax + SOCKET.Protocol], IP_PROTO_UDP
|
|
||||||
je .free
|
|
||||||
|
|
||||||
cmp [eax + SOCKET.Protocol], IP_PROTO_ICMP
|
|
||||||
je .free
|
|
||||||
|
|
||||||
cmp [eax + SOCKET.Protocol], IP_PROTO_IP
|
|
||||||
je .free
|
|
||||||
|
|
||||||
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
|
cmp [eax + SOCKET.Protocol], IP_PROTO_TCP
|
||||||
je .tcp
|
je .tcp
|
||||||
|
|
||||||
jmp s_error
|
.free:
|
||||||
|
call SOCKET_free
|
||||||
|
ret
|
||||||
|
|
||||||
.tcp:
|
.tcp:
|
||||||
cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED ; state must be LISTEN, SYN_SENT or CLOSED
|
cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED ; state must be LISTEN, SYN_SENT or CLOSED
|
||||||
@ -741,15 +738,6 @@ SOCKET_close:
|
|||||||
call TCP_usrclosed
|
call TCP_usrclosed
|
||||||
call TCP_output ;;;; Fixme: is this nescessary??
|
call TCP_output ;;;; Fixme: is this nescessary??
|
||||||
|
|
||||||
;;; TODO: wait for successfull termination if blocking socket
|
|
||||||
mov dword [esp+32], 0
|
|
||||||
|
|
||||||
ret
|
|
||||||
|
|
||||||
.free:
|
|
||||||
call SOCKET_free
|
|
||||||
mov dword [esp+32], 0
|
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
@ -838,6 +826,7 @@ SOCKET_receive_local:
|
|||||||
mov ebx, [TASK_BASE]
|
mov ebx, [TASK_BASE]
|
||||||
mov ebx, [ebx + TASKDATA.pid]
|
mov ebx, [ebx + TASKDATA.pid]
|
||||||
mov [eax + SOCKET.PID], ebx
|
mov [eax + SOCKET.PID], ebx
|
||||||
|
mov [eax + SOCKET.TID], ebx ; currently TID = PID in kolibrios :(
|
||||||
@@:
|
@@:
|
||||||
|
|
||||||
mov [eax + SOCKET.rcv_proc], SOCKET_receive_stream
|
mov [eax + SOCKET.rcv_proc], SOCKET_receive_stream
|
||||||
@ -972,6 +961,7 @@ SOCKET_send_local:
|
|||||||
mov ebx, [TASK_BASE]
|
mov ebx, [TASK_BASE]
|
||||||
mov ebx, [ebx + TASKDATA.pid]
|
mov ebx, [ebx + TASKDATA.pid]
|
||||||
mov [eax + SOCKET.PID], ebx
|
mov [eax + SOCKET.PID], ebx
|
||||||
|
mov [eax + SOCKET.TID], ebx ; currently TID = PID in kolibrios :(
|
||||||
@@:
|
@@:
|
||||||
mov [eax + SOCKET.snd_proc], SOCKET_send_local_
|
mov [eax + SOCKET.snd_proc], SOCKET_send_local_
|
||||||
|
|
||||||
@ -1608,8 +1598,12 @@ SOCKET_block:
|
|||||||
; Suspend the thread
|
; Suspend the thread
|
||||||
push edx
|
push edx
|
||||||
mov edx, [TASK_BASE]
|
mov edx, [TASK_BASE]
|
||||||
DEBUGF 1,"SOCKET_block: suspending PID: %u\n", [edx + TASKDATA.pid]
|
|
||||||
mov [edx + TASKDATA.state], 1 ; Suspended
|
mov [edx + TASKDATA.state], 1 ; Suspended
|
||||||
|
|
||||||
|
; Remember the thread ID so we can wake it up again
|
||||||
|
mov edx, [edx + TASKDATA.pid]
|
||||||
|
DEBUGF 1,"SOCKET_block: suspending thread: %u\n", edx
|
||||||
|
mov [eax + SOCKET.TID], edx
|
||||||
pop edx
|
pop edx
|
||||||
|
|
||||||
call change_task
|
call change_task
|
||||||
@ -1649,7 +1643,7 @@ SOCKET_notify:
|
|||||||
; socket exists and is of non blocking type.
|
; socket exists and is of non blocking type.
|
||||||
; We'll try to flag an event to the thread
|
; We'll try to flag an event to the thread
|
||||||
|
|
||||||
mov eax, [eax + SOCKET.PID]
|
mov eax, [eax + SOCKET.TID]
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .done
|
jz .done
|
||||||
mov ecx, 1
|
mov ecx, 1
|
||||||
@ -1680,7 +1674,7 @@ SOCKET_notify:
|
|||||||
and [eax + SOCKET.state], not SS_BLOCKED
|
and [eax + SOCKET.state], not SS_BLOCKED
|
||||||
|
|
||||||
; Find the thread's TASK_DATA
|
; Find the thread's TASK_DATA
|
||||||
mov eax, [eax + SOCKET.PID]
|
mov eax, [eax + SOCKET.TID]
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .error
|
jz .error
|
||||||
xor ecx, ecx
|
xor ecx, ecx
|
||||||
@ -1769,6 +1763,7 @@ SOCKET_alloc:
|
|||||||
mov ebx, [TASK_BASE]
|
mov ebx, [TASK_BASE]
|
||||||
mov ebx, [ebx + TASKDATA.pid]
|
mov ebx, [ebx + TASKDATA.pid]
|
||||||
mov [eax + SOCKET.PID], ebx
|
mov [eax + SOCKET.PID], ebx
|
||||||
|
mov [eax + SOCKET.TID], ebx ; currently TID = PID in kolibrios :(
|
||||||
|
|
||||||
; init mutex
|
; init mutex
|
||||||
pusha
|
pusha
|
||||||
@ -2064,7 +2059,6 @@ SOCKET_process_end:
|
|||||||
|
|
||||||
.next_socket:
|
.next_socket:
|
||||||
mov ebx, [ebx + SOCKET.NextPtr]
|
mov ebx, [ebx + SOCKET.NextPtr]
|
||||||
.test_socket:
|
|
||||||
test ebx, ebx
|
test ebx, ebx
|
||||||
jz .done
|
jz .done
|
||||||
|
|
||||||
@ -2074,23 +2068,11 @@ SOCKET_process_end:
|
|||||||
DEBUGF 1, "SOCKET_process_end: killing socket %x\n", ebx
|
DEBUGF 1, "SOCKET_process_end: killing socket %x\n", ebx
|
||||||
|
|
||||||
mov [ebx + SOCKET.PID], 0
|
mov [ebx + SOCKET.PID], 0
|
||||||
|
|
||||||
cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP
|
|
||||||
je .tcp
|
|
||||||
|
|
||||||
; The socket is stateless, just kill it right away!
|
|
||||||
|
|
||||||
mov eax, ebx
|
mov eax, ebx
|
||||||
mov ebx, [ebx + SOCKET.NextPtr]
|
pusha
|
||||||
call SOCKET_free
|
call SOCKET_close.socket
|
||||||
jmp .test_socket
|
popa
|
||||||
|
jmp .next_socket
|
||||||
.tcp:
|
|
||||||
push [ebx + SOCKET.NextPtr]
|
|
||||||
mov eax, ebx
|
|
||||||
call TCP_disconnect
|
|
||||||
pop ebx
|
|
||||||
jmp .test_socket
|
|
||||||
|
|
||||||
.done:
|
.done:
|
||||||
pop ebx
|
pop ebx
|
||||||
|
Loading…
Reference in New Issue
Block a user