Adding telnetd for posix
This commit is contained in:
@ -96,16 +96,21 @@ decimal
|
||||
|
||||
( errno.h )
|
||||
11 constant EAGAIN
|
||||
32 constant EPIPE
|
||||
|
||||
( Signal Handling )
|
||||
0 constant SIG_DFL
|
||||
1 constant SIG_IGN
|
||||
|
||||
( Signals )
|
||||
1 constant SIGHUP
|
||||
2 constant SIGINT
|
||||
9 constant SIGKILL
|
||||
10 constant SIGPIPE
|
||||
7 constant SIGBUS
|
||||
13 constant SIGPIPE
|
||||
|
||||
( Ignore SIGPIPE )
|
||||
SIGPIPE SIG_IGN signal drop
|
||||
|
||||
( Modes )
|
||||
octal 777 constant 0777 decimal
|
||||
|
||||
15
ueforth/posix/sockets.fs
Normal file
15
ueforth/posix/sockets.fs
Normal file
@ -0,0 +1,15 @@
|
||||
( Sockets )
|
||||
posix definitions
|
||||
|
||||
z" socket" 3 sysfunc socket
|
||||
z" bind" 3 sysfunc bind
|
||||
z" listen" 2 sysfunc listen
|
||||
z" connect" 3 sysfunc connect
|
||||
z" accept" 3 sysfunc accept
|
||||
z" poll" 3 sysfunc poll
|
||||
|
||||
1 constant SOCK_STREAM
|
||||
2 constant AF_INET
|
||||
16 constant sizeof(sockaddr_in)
|
||||
|
||||
forth definitions
|
||||
41
ueforth/posix/telnetd.fs
Normal file
41
ueforth/posix/telnetd.fs
Normal file
@ -0,0 +1,41 @@
|
||||
( WebServer )
|
||||
include posix/sockets.fs
|
||||
|
||||
vocabulary telnetd telnetd definitions also posix
|
||||
|
||||
8080 constant port
|
||||
-1 value sockfd -1 value clientfd
|
||||
: bs, ( n -- ) dup 256 / c, c, ;
|
||||
: s, ( n -- ) dup c, 256 / c, ;
|
||||
: l, ( n -- ) dup s, 65536 / s, ;
|
||||
create telnet-port AF_INET s, port bs, 0 l, 0 ,
|
||||
create client sizeof(sockaddr_in) allot variable client-len
|
||||
|
||||
defer broker
|
||||
|
||||
: telnet-type ( a n -- ) clientfd -rot write 0< if 2drop broker then ;
|
||||
: telnet-key ( -- n ) 0 >r clientfd rp@ 1 read 0< if rdrop broker then r> ;
|
||||
|
||||
: connection ( n -- )
|
||||
dup 0< if drop exit then to clientfd
|
||||
['] telnet-key is key
|
||||
['] telnet-type is type quit ;
|
||||
|
||||
: broker-connection
|
||||
rp0 rp! sp0 sp!
|
||||
begin
|
||||
['] stdin-key is key ['] stdout-write is type
|
||||
." Listening on port " port . cr
|
||||
sockfd client client-len accept
|
||||
." Connected: " dup . cr connection
|
||||
again ;
|
||||
' broker-connection is broker
|
||||
|
||||
: server
|
||||
AF_INET SOCK_STREAM 0 socket to sockfd
|
||||
sockfd telnet-port sizeof(sockaddr_in) bind throw
|
||||
sockfd 10 listen throw broker ;
|
||||
|
||||
only forth definitions
|
||||
|
||||
telnetd server
|
||||
Reference in New Issue
Block a user