1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
22 var testing_id
: Int is lazy
do
23 var id
= "NIT_TESTING_ID".environ
24 return if id
.is_empty
then 0 else id
.to_i
27 # Config for test sockets
28 var tcp_addr
= "localhost"
29 var tcp_port
: Int = 20000 + testing_id
30 var unix_socket_path
= "/tmp/libevent_test{testing_id}.sck"
33 class TestConnectionFactory
34 super ConnectionFactory
36 redef fun spawn_connection
(buf
, address
)
38 print
"[Server] New client: {address}"
40 var conn
= new TestConnection(buf
)
41 print
"[Server] Write: Hi"
50 redef fun read_callback
(content
)
52 0.2.sleep
# Forcing the server output after the client output
53 printn
"[Server] Read: {content}"
62 var event_base
= new NativeEventBase
63 var factory
= new TestConnectionFactory(event_base
)
66 factory
.bind_tcp
(tcp_addr
, tcp_port
)
68 # Bind UNIX domain socket
69 factory
.bind_unix unix_socket_path
80 if testing_id
== 0 then print
"[Client] {cmd}"
84 # First, launch a server in the background
85 var server
= new ServerThread
89 # Test what should succeed
90 system
"echo 'Hello TCP' | nc -N {tcp_addr} {tcp_port}"
91 system
"echo 'Hello UNIX' | nc -NU {unix_socket_path}"