Skip to content

Commit

Permalink
Merge pull request #3509 from maxteufel/net_connection_handler
Browse files Browse the repository at this point in the history
lib/net: rename `Request_Handler` to `Connection_Handler`
  • Loading branch information
michaellilltokiwa committed Aug 12, 2024
2 parents b7dbd2e + bd4cd55 commit 0fc172b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
12 changes: 6 additions & 6 deletions lib/net/client.fz
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@
#
# Minimal example:
#
# rh : net.Request_Handler unit is
# handle_request unit =>
# ch : net.Connection_Handler unit is
# handle_connection unit =>
# say net.channel.env.get_peer_address
#
# net.client rh net.family.ipv4 net.protocol.tcp "tokiwa.software" (u16 80) # NYI: type inference
# net.client ch net.family.ipv4 net.protocol.tcp "tokiwa.software" (u16 80) # NYI: type inference
#
#
# Blocks until connection is establised.
# NYI blocking / none blocking
#
public client(T type, LM type : mutate, rh Request_Handler T, f net.family.val, p net.protocol.val, host String, port u16) outcome T
public client(T type, LM type : mutate, ch Connection_Handler T, f net.family.val, p net.protocol.val, host String, port u16) outcome T
=>
s := net.socket_type.by_protocol p
fuzion.sys.net.connect f.as_num s.as_num p.as_num host port
.bind T (desc)->
# NYI install custom thread spawn effect
# NYI: BUG: (try net.request_handler).on ()->
# NYI: BUG: (try net.connection_handler).on ()->

res := (io.buffered.reader LM (read_provider desc) 1024).with ()->
(io.buffered.writer LM (write_provider desc) 1024).with ()->
(net.channel desc).go ()->
rh.handle_request
ch.handle_connection

_ := fuzion.sys.net.close desc

Expand Down
7 changes: 4 additions & 3 deletions lib/net/request_handler.fz → lib/net/connection_handler.fz
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
#
# -----------------------------------------------------------------------

# definition of a request handler.
# definition of a connection handler.
#
public Request_Handler(T type) ref is
public Connection_Handler(T type) ref is

public handle_request T ! io.buffered.reader, net.channel => abstract
public handle_connection T ! io.buffered.reader, io.buffered.writer, net.channel
=> abstract
6 changes: 3 additions & 3 deletions lib/net/server.fz
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ is
# does nothing for UDP etc.
# blocks until connection is established
# NYI we may want to close server on certain errors?
public accept(T type, LM type : mutate, rh Request_Handler T) outcome T =>
public accept(T type, LM type : mutate, ch Connection_Handler T) outcome T =>
match state
d i64 =>
match fuzion.sys.net.accept d
Expand All @@ -77,13 +77,13 @@ is
# spawn(code ()->unit) concur.thread.spawned =>
# panic "may not spawn threads in request handler"
# (concur.thread no_threads).go ()->
# _ := request_handler.env.handle_request (channel desc)
# _ := connection_handler.env.handle_connection (channel desc)
# fuzion.sys.net.close desc

res := (io.buffered.reader LM (read_provider desc) 1024).with ()->
(io.buffered.writer LM (write_provider desc) 1024).with ()->
(net.channel desc).go ()->
rh.handle_request
ch.handle_connection

_ := fuzion.sys.net.close desc

Expand Down
12 changes: 6 additions & 6 deletions tests/sockets/sockets_test.fz
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ sockets_test is



rh : net.Request_Handler unit is
ch : net.Connection_Handler unit is

redef handle_request unit =>
redef handle_connection unit =>

chan => net.channel.env

Expand Down Expand Up @@ -76,7 +76,7 @@ sockets_test is



while net.server.is_active && match net.server.accept unit LM rh
while net.server.is_active && match net.server.accept unit LM ch
e error => false
* => true
do
Expand All @@ -93,9 +93,9 @@ sockets_test is
client(family net.family.val, protocol net.protocol.val, host String, port u16, num i32) =>
lm : mutate is
lm.go ()->
rh : net.Request_Handler String is
ch : net.Connection_Handler String is

redef handle_request =>
redef handle_connection =>

chan => net.channel.env

Expand Down Expand Up @@ -124,7 +124,7 @@ sockets_test is
* => panic "NI"


match net.client String lm rh family protocol host port
match net.client String lm ch family protocol host port
err error =>
say "$protocol/$family-client {sockets_test.client.this.num}, $host:$port: error establishing connection"
str String =>
Expand Down

0 comments on commit 0fc172b

Please sign in to comment.