echo server, multiple clients, lines <256 bytes
This commit is contained in:
parent
d54596514c
commit
29f54ba779
6 changed files with 304 additions and 112 deletions
104
client.s
Normal file
104
client.s
Normal file
|
@ -0,0 +1,104 @@
|
|||
; Errors (in rax):
|
||||
; 0 - EOF
|
||||
; -1024 - line too long
|
||||
; other negative - from read(2)
|
||||
; Arguments:
|
||||
; rdi - fd
|
||||
; rsi - address of client within clients array
|
||||
; rdx - pollfds index
|
||||
client__pollin:
|
||||
push rdi
|
||||
push rsi
|
||||
push rdx
|
||||
|
||||
mov r10, 0
|
||||
mov r10b, [rsi + 4 + 2] ; buffer_len
|
||||
|
||||
mov rdx, 0
|
||||
mov dl, 255
|
||||
sub dl, r10b ; rdx = 255 - buffer_len
|
||||
add rsi, 8
|
||||
add rsi, r10
|
||||
call readline
|
||||
|
||||
mov r10, rdi
|
||||
|
||||
pop rdx
|
||||
pop rsi
|
||||
pop rdi
|
||||
|
||||
cmp rax, 0
|
||||
jle return
|
||||
|
||||
add [rsi + 4 + 2], al ; buffer_len += rax
|
||||
|
||||
cmp r10, 0
|
||||
jg client__pollin__complete_line
|
||||
|
||||
add [rsi + 4 + 1], al ; line_len += rax
|
||||
ret
|
||||
|
||||
client__pollin__complete_line:
|
||||
add [rsi + 4 + 1], r10b ; line_len += r10
|
||||
mov word [pollfds + rdx * pollfd_size + 4], POLLOUT
|
||||
ret
|
||||
|
||||
; rdi - fd
|
||||
; rsi - address of client within clients array
|
||||
; rdx - pollfds index
|
||||
client__pollout:
|
||||
push rdi
|
||||
push rsi
|
||||
push rdx
|
||||
|
||||
mov rax, SYS_WRITE
|
||||
mov rdx, 0
|
||||
mov dl, [rsi + 4 + 1]
|
||||
add rsi, 8
|
||||
syscall
|
||||
|
||||
pop rdx
|
||||
pop rsi
|
||||
pop rdi
|
||||
|
||||
cmp rax, 0
|
||||
jl return
|
||||
|
||||
mov r10, rsi
|
||||
add r10, 8
|
||||
mov r11, 0
|
||||
mov r11b, [rsi + 4 + 2]
|
||||
sub r11, rax
|
||||
add r11, r10
|
||||
|
||||
client__pollout__shunt:
|
||||
cmp r10, r11
|
||||
jge client__pollout__shunt__finished
|
||||
mov r8b, [r10 + rax]
|
||||
mov [r10], r8b
|
||||
add r10, 1
|
||||
jmp client__pollout__shunt
|
||||
|
||||
client__pollout__shunt__finished:
|
||||
sub [rsi + 4 + 2], al ; buffer_len -= rax
|
||||
sub [rsi + 4 + 1], al ; line_len -= rax
|
||||
cmp byte [rsi + 4 + 1], 0
|
||||
je client__pollout__wrote_line
|
||||
ret
|
||||
|
||||
client__pollout__wrote_line:
|
||||
mov word [pollfds + rdx * pollfd_size + 4], POLLIN
|
||||
ret
|
||||
|
||||
; rdi - fd
|
||||
client__shutdown_close:
|
||||
mov rax, SYS_SHUTDOWN
|
||||
push rdi
|
||||
mov rsi, SHUT_RDWR
|
||||
syscall
|
||||
|
||||
mov rax, SYS_CLOSE
|
||||
pop rdi
|
||||
syscall
|
||||
|
||||
ret
|
Loading…
Add table
Add a link
Reference in a new issue