Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 322 → Rev 323

/kernel/trunk/network/socket.inc
207,12 → 207,8
 
xchg bh, bl
mov [eax + SOCKET.LocalPort], bx
; mov [eax + 12], byte bh ; Local port ( LS 16 bits )
; mov [eax + 13], byte bl ; Local port ( LS 16 bits )
xchg ch, cl
mov [eax + SOCKET.RemotePort], cx
; mov [eax + 20], ch ; Remote Port ( LS 16 bits )
; mov [eax + 21], cl ; Remote Port ( LS 16 bits )
 
mov ebx, [stack_ip]
mov [eax + SOCKET.LocalIP], ebx
547,7 → 543,74
ret
 
 
;***************************************************************************
; Function
; socket_read_packet
;
; Description
; socket # in ebx
; datapointer # in ecx
; buffer size in edx
; returns # of bytes copied in eax
;
;***************************************************************************
socket_read_packet:
Index2RealAddr ebx ; get real socket address
mov eax, [ebx + SOCKET.rxDataCount] ; get count of bytes
test eax, eax ; if count of bytes is zero..
jz .exit ; exit function (eax will be zero)
 
test edx, edx ; if buffer size is zero, copy all data
jz .copyallbytes
cmp edx, eax ; if buffer size is larger then the bytes of data, copy all data
jge .copyallbytes
 
sub eax, edx ; store new count (data bytes in buffer - bytes we're about to copy)
mov [ebx + SOCKET.rxDataCount], eax ;
push eax
mov eax, edx ; number of bytes we want to copy must be in eax
call .startcopy ; copy to the application
 
mov esi, ebx ; now we're going to copy the remaining bytes to the beginning
add esi, SOCKETHEADERSIZE ; we dont need to copy the header
mov edi, esi ; edi is where we're going to copy to
add esi, edx ; esi is from where we copy
pop ecx ; count of bytes we have left
push ecx ; push it again so we can re-use it later
shr ecx, 2 ; divide eax by 4
cld
rep movsd ; copy all full dwords
pop ecx
and ecx, 3
rep movsb ; copy remaining bytes
 
ret ; at last, exit
 
.copyallbytes:
xor esi, esi
mov [ebx + SOCKET.rxDataCount], esi ; store new count (zero)
 
.startcopy:
mov edi, ecx ;
add edi, std_application_base_address ; get data pointer to buffer in application
 
mov esi, ebx ;
add esi, SOCKETHEADERSIZE ; we dont need to copy the header
mov ecx, eax ; eax is count of bytes
push ecx
shr ecx, 2 ; divide eax by 4
cld ; copy all full dwords
rep movsd ;
pop ecx
and ecx, 3
rep movsb ; copy the rest bytes
 
.exit:
ret ; exit, or go back to shift remaining bytes if any
 
 
 
 
;***************************************************************************
; Function
; socket_write