Better text printing for TCPserv (net branch)
git-svn-id: svn://kolibrios.org@2556 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
a1174dce46
commit
c552138150
@ -1,16 +1,16 @@
|
|||||||
use32
|
use32
|
||||||
; standard header
|
; standard header
|
||||||
db 'MENUET01' ; signature
|
db 'MENUET01' ; signature
|
||||||
dd 1 ; header version
|
dd 1 ; header version
|
||||||
dd start ; entry point
|
dd start ; entry point
|
||||||
dd i_end ; initialized size
|
dd i_end ; initialized size
|
||||||
dd mem ; required memory
|
dd mem ; required memory
|
||||||
dd mem ; stack pointer
|
dd mem ; stack pointer
|
||||||
dd 0 ; parameters
|
dd 0 ; parameters
|
||||||
dd 0 ; path
|
dd 0 ; path
|
||||||
|
|
||||||
|
|
||||||
BUFFERSIZE equ 1500
|
BUFFERSIZE equ 1500
|
||||||
; useful includes
|
; useful includes
|
||||||
include '../macros.inc'
|
include '../macros.inc'
|
||||||
purge mov,add,sub
|
purge mov,add,sub
|
||||||
@ -22,116 +22,120 @@ include '../network.inc'
|
|||||||
; entry point
|
; entry point
|
||||||
start:
|
start:
|
||||||
; load libraries
|
; load libraries
|
||||||
stdcall dll.Load, @IMPORT
|
stdcall dll.Load, @IMPORT
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jnz exit
|
jnz exit
|
||||||
|
|
||||||
; initialize console
|
; initialize console
|
||||||
push 1
|
push 1
|
||||||
call [con_start]
|
call [con_start]
|
||||||
push title
|
push title
|
||||||
push 25
|
push 25
|
||||||
push 80
|
push 80
|
||||||
push 25
|
push 25
|
||||||
push 80
|
push 80
|
||||||
call [con_init]
|
call [con_init]
|
||||||
|
|
||||||
mcall 40, 1 shl 7 ; we only want network events
|
mcall 40, 1 shl 7 ; we only want network events
|
||||||
|
|
||||||
push str1
|
push str1
|
||||||
call [con_write_asciiz]
|
call [con_write_asciiz]
|
||||||
|
|
||||||
mcall socket, AF_INET4, SOCK_STREAM, 0
|
mcall socket, AF_INET4, SOCK_STREAM, 0
|
||||||
cmp eax, -1
|
cmp eax, -1
|
||||||
je sock_err
|
je sock_err
|
||||||
|
|
||||||
mov [socketnum], eax
|
mov [socketnum], eax
|
||||||
|
|
||||||
;; mcall setsockopt, [socketnum], SOL_SOCKET, SO_REUSEADDR, &yes,
|
;; mcall setsockopt, [socketnum], SOL_SOCKET, SO_REUSEADDR, &yes,
|
||||||
;; cmp eax, -1
|
;; cmp eax, -1
|
||||||
;; je opt_err
|
;; je opt_err
|
||||||
|
|
||||||
mcall bind, [socketnum], sockaddr1, sockaddr1.length
|
mcall bind, [socketnum], sockaddr1, sockaddr1.length
|
||||||
cmp eax, -1
|
cmp eax, -1
|
||||||
je bind_err
|
je bind_err
|
||||||
|
|
||||||
mcall listen, [socketnum], 10 ; Backlog = 10
|
mcall listen, [socketnum], 10 ; Backlog = 10
|
||||||
cmp eax, -1
|
cmp eax, -1
|
||||||
je listen_err
|
je listen_err
|
||||||
|
|
||||||
push str2
|
push str2
|
||||||
call [con_write_asciiz]
|
call [con_write_asciiz]
|
||||||
|
|
||||||
mcall 10
|
mcall 10
|
||||||
|
|
||||||
mcall accept, [socketnum], sockaddr1, sockaddr1.length
|
mcall accept, [socketnum], sockaddr1, sockaddr1.length
|
||||||
cmp eax, -1
|
cmp eax, -1
|
||||||
je acpt_err
|
je acpt_err
|
||||||
|
|
||||||
mov [socketnum2], eax
|
mov [socketnum2], eax
|
||||||
|
|
||||||
;; mcall close, [socketnum]
|
;; mcall close, [socketnum]
|
||||||
|
|
||||||
mcall send, [socketnum2], hello, hello.length
|
mcall send, [socketnum2], hello, hello.length
|
||||||
|
|
||||||
.loop:
|
.loop:
|
||||||
mcall 10
|
mcall 10
|
||||||
|
|
||||||
mcall recv, [socketnum2], buffer, buffer.length
|
mcall recv, [socketnum2], buffer, buffer.length
|
||||||
|
cmp eax, -1
|
||||||
|
je .loop
|
||||||
|
|
||||||
push buffer
|
mov byte [buffer + eax], 0
|
||||||
call [con_write_asciiz]
|
|
||||||
|
|
||||||
jmp .loop
|
push buffer
|
||||||
|
call [con_write_asciiz]
|
||||||
|
|
||||||
|
jmp .loop
|
||||||
|
|
||||||
acpt_err:
|
acpt_err:
|
||||||
push str8
|
push str8
|
||||||
call [con_write_asciiz]
|
call [con_write_asciiz]
|
||||||
jmp done
|
jmp done
|
||||||
|
|
||||||
listen_err:
|
listen_err:
|
||||||
push str3
|
push str3
|
||||||
call [con_write_asciiz]
|
call [con_write_asciiz]
|
||||||
jmp done
|
jmp done
|
||||||
|
|
||||||
bind_err:
|
bind_err:
|
||||||
push str4
|
push str4
|
||||||
call [con_write_asciiz]
|
call [con_write_asciiz]
|
||||||
jmp done
|
jmp done
|
||||||
|
|
||||||
sock_err:
|
sock_err:
|
||||||
push str6
|
push str6
|
||||||
call [con_write_asciiz]
|
call [con_write_asciiz]
|
||||||
jmp done
|
jmp done
|
||||||
|
|
||||||
done:
|
done:
|
||||||
call [con_getch2]
|
call [con_getch2]
|
||||||
push 1
|
push 1
|
||||||
call [con_exit]
|
call [con_exit]
|
||||||
exit:
|
exit:
|
||||||
mcall -1
|
mcall -1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; data
|
; data
|
||||||
title db 'TCP stream server - test',0
|
title db 'TCP stream server - test',0
|
||||||
str1 db 'Opening socket',10, 0
|
str1 db 'Opening socket',10, 0
|
||||||
str2 db 'Listening for incoming connections...',10,0
|
str2 db 'Listening for incoming connections...',10,0
|
||||||
str3 db 'Listen error',10,10,0
|
str3 db 'Listen error',10,10,0
|
||||||
str4 db 'Bind error',10,10,0
|
str4 db 'Bind error',10,10,0
|
||||||
str5 db 'Setsockopt error.',10,10,0
|
str5 db 'Setsockopt error.',10,10,0
|
||||||
str6 db 'Could not open socket',10,10,0
|
str6 db 'Could not open socket',10,10,0
|
||||||
str7 db 'Got data!',10,10,0
|
str7 db 'Got data!',10,10,0
|
||||||
str8 db 'Error accepting connection',10,10,0
|
str8 db 'Error accepting connection',10,10,0
|
||||||
|
|
||||||
hello db 'Hello world!',0
|
hello db 'Hello world!',0
|
||||||
.length = $ - hello
|
.length = $ - hello
|
||||||
|
|
||||||
sockaddr1:
|
sockaddr1:
|
||||||
dw AF_INET4
|
dw AF_INET4
|
||||||
.port dw 23
|
.port dw 23
|
||||||
.ip dd 0
|
.ip dd 0
|
||||||
rb 10
|
rb 10
|
||||||
.length = $ - sockaddr1
|
.length = $ - sockaddr1
|
||||||
|
|
||||||
; import
|
; import
|
||||||
@ -140,23 +144,23 @@ align 4
|
|||||||
|
|
||||||
library console, 'console.obj'
|
library console, 'console.obj'
|
||||||
|
|
||||||
import console, \
|
import console, \
|
||||||
con_start, 'START', \
|
con_start, 'START', \
|
||||||
con_init, 'con_init', \
|
con_init, 'con_init', \
|
||||||
con_write_asciiz, 'con_write_asciiz', \
|
con_write_asciiz, 'con_write_asciiz', \
|
||||||
con_exit, 'con_exit', \
|
con_exit, 'con_exit', \
|
||||||
con_gets, 'con_gets',\
|
con_gets, 'con_gets',\
|
||||||
con_cls, 'con_cls',\
|
con_cls, 'con_cls',\
|
||||||
con_printf, 'con_printf',\
|
con_printf, 'con_printf',\
|
||||||
con_getch2, 'con_getch2',\
|
con_getch2, 'con_getch2',\
|
||||||
con_set_cursor_pos, 'con_set_cursor_pos'
|
con_set_cursor_pos, 'con_set_cursor_pos'
|
||||||
i_end:
|
i_end:
|
||||||
|
|
||||||
socketnum dd ?
|
socketnum dd ?
|
||||||
socketnum2 dd ?
|
socketnum2 dd ?
|
||||||
buffer rb BUFFERSIZE
|
buffer rb BUFFERSIZE
|
||||||
.length = BUFFERSIZE
|
.length = BUFFERSIZE
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
rb 4096 ; stack
|
rb 4096 ; stack
|
||||||
mem:
|
mem:
|
||||||
|
Loading…
Reference in New Issue
Block a user