Skip to content

Commit ec973f5

Browse files
authored
x.websocket: move to net.websocket module (#10648)
1 parent c44a47a commit ec973f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1656
-67
lines changed

.github/workflows/websockets.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ jobs:
2727
- name: v doctor
2828
run: ./v doctor
2929
- name: Run websockets tests
30-
run: ./v -g test vlib/x/websocket/
30+
run: ./v -g test vlib/net/websocket/
3131

3232
## Autobahn integrations tests
3333
- name: Run autobahn services
34-
run: docker-compose -f ${{github.workspace}}/vlib/x/websocket/tests/autobahn/docker-compose.yml up -d
34+
run: docker-compose -f ${{github.workspace}}/vlib/net/websocket/tests/autobahn/docker-compose.yml up -d
3535

3636
- name: Wait for the service to start
3737
run: sleep 10s
3838

3939
- name: Build client test
40-
run: docker exec autobahn_client "/src/v" "/src/vlib/x/websocket/tests/autobahn/autobahn_client.v"
40+
run: docker exec autobahn_client "/src/v" "/src/vlib/net/websocket/tests/autobahn/autobahn_client.v"
4141
- name: Run client test
42-
run: docker exec autobahn_client "/src/vlib/x/websocket/tests/autobahn/autobahn_client"
42+
run: docker exec autobahn_client "/src/vlib/net/websocket/tests/autobahn/autobahn_client"
4343

4444
- name: Build client wss test
45-
run: docker exec autobahn_client "/src/v" "/src/vlib/x/websocket/tests/autobahn/autobahn_client_wss.v"
45+
run: docker exec autobahn_client "/src/v" "/src/vlib/net/websocket/tests/autobahn/autobahn_client_wss.v"
4646

4747
- name: Run client wss test
48-
run: docker exec autobahn_client "/src/vlib/x/websocket/tests/autobahn/autobahn_client_wss"
48+
run: docker exec autobahn_client "/src/vlib/net/websocket/tests/autobahn/autobahn_client_wss"
4949
- name: Run server test
5050
run: docker exec autobahn_server "wstest" "-m" "fuzzingclient" "-s" "/config/fuzzingclient.json"
5151

cmd/tools/vtest-self.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ const (
4444
'vlib/vweb/request_test.v',
4545
'vlib/net/http/request_test.v',
4646
'vlib/vweb/route_test.v',
47-
'vlib/x/websocket/websocket_test.v',
47+
'vlib/net/websocket/websocket_test.v',
4848
'vlib/crypto/rand/crypto_rand_read_test.v',
4949
]
5050
skip_with_fsanitize_address = [
51-
'vlib/x/websocket/websocket_test.v',
51+
'vlib/net/websocket/websocket_test.v',
5252
]
5353
skip_with_fsanitize_undefined = [
5454
'do_not_remove',
@@ -83,7 +83,7 @@ const (
8383
'vlib/vweb/request_test.v',
8484
'vlib/net/http/request_test.v',
8585
'vlib/vweb/route_test.v',
86-
'vlib/x/websocket/websocket_test.v',
86+
'vlib/net/websocket/websocket_test.v',
8787
'vlib/net/http/http_httpbin_test.v',
8888
'vlib/net/http/header_test.v',
8989
]
@@ -98,7 +98,7 @@ const (
9898
'vlib/v/tests/orm_sub_struct_test.v',
9999
'vlib/net/websocket/ws_test.v',
100100
'vlib/net/unix/unix_test.v',
101-
'vlib/x/websocket/websocket_test.v',
101+
'vlib/net/websocket/websocket_test.v',
102102
'vlib/vweb/tests/vweb_test.v',
103103
'vlib/vweb/request_test.v',
104104
'vlib/net/http/request_test.v',

examples/websocket/client-server/client.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module main
22

33
import os
4-
import x.websocket
4+
import net.websocket
55
import term
66

77
// This client should be compiled an run in different konsoles

examples/websocket/client-server/server.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module main
22

3-
import x.websocket
3+
import net.websocket
44
import term
55

66
// this server accepts client connections and broadcast all messages to other connected clients

examples/websocket/ping.v

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module main
22

33
import time
44
import os
5-
import x.websocket
5+
import net.websocket
66

77
fn main() {
88
println('press enter to quit...\n')
@@ -12,6 +12,8 @@ fn main() {
1212
os.get_line()
1313
}
1414

15+
// start_server starts the websocket server, it receives messages
16+
// and send it back to the client that sent it
1517
fn start_server() ? {
1618
mut s := websocket.new_server(.ip6, 30000, '')
1719
// Make that in execution test time give time to execute at least one time
@@ -36,6 +38,8 @@ fn start_server() ? {
3638
}
3739
}
3840

41+
// start_client starts the websocket client, it writes a message to
42+
// the server and prints all the messages received
3943
fn start_client() ? {
4044
mut ws := websocket.new_client('ws://localhost:30000') ?
4145
// mut ws := websocket.new_client('wss://echo.websocket.org:443')?

vlib/x/openssl/openssl.v renamed to vlib/net/openssl/ssl_connection.v

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
module openssl
22

33
import net
4-
import net.openssl as nssl
54
import time
65

6+
// SSLConn is the current connection
7+
pub struct SSLConn {
8+
mut:
9+
sslctx &C.SSL_CTX
10+
ssl &C.SSL
11+
handle int
12+
duration time.Duration
13+
}
14+
15+
// new_ssl_conn instance an new SSLCon struct
16+
pub fn new_ssl_conn() &SSLConn {
17+
return &SSLConn{
18+
sslctx: 0
19+
ssl: 0
20+
handle: 0
21+
}
22+
}
23+
24+
// Select operation
25+
enum Select {
26+
read
27+
write
28+
except
29+
}
30+
731
// shutdown closes the ssl connection and do clean up
832
pub fn (mut s SSLConn) shutdown() ? {
933
if s.ssl != 0 {
1034
mut res := 0
1135
for {
1236
res = C.SSL_shutdown(voidptr(s.ssl))
1337
if res < 0 {
14-
err_res := nssl.ssl_error(res, s.ssl) or {
38+
err_res := ssl_error(res, s.ssl) or {
1539
break // We break to free rest of resources
1640
}
1741
if err_res == .ssl_error_want_read {
@@ -99,7 +123,7 @@ pub fn (mut s SSLConn) connect(mut tcp_conn net.TcpConn, hostname string) ? {
99123
for {
100124
res = C.SSL_connect(voidptr(s.ssl))
101125
if res != 1 {
102-
err_res := nssl.ssl_error(res, s.ssl) ?
126+
err_res := ssl_error(res, s.ssl) ?
103127
if err_res == .ssl_error_want_read {
104128
for {
105129
ready := @select(s.handle, .read, s.duration) ?
@@ -128,7 +152,7 @@ pub fn (mut s SSLConn) socket_read_into_ptr(buf_ptr &byte, len int) ?int {
128152
for {
129153
res = C.SSL_read(voidptr(s.ssl), buf_ptr, len)
130154
if res < 0 {
131-
err_res := nssl.ssl_error(res, s.ssl) ?
155+
err_res := ssl_error(res, s.ssl) ?
132156
if err_res == .ssl_error_want_read {
133157
for {
134158
ready := @select(s.handle, .read, s.duration) ?
@@ -170,7 +194,7 @@ pub fn (mut s SSLConn) write(bytes []byte) ?int {
170194
remaining := bytes.len - total_sent
171195
mut sent := C.SSL_write(voidptr(s.ssl), ptr, remaining)
172196
if sent <= 0 {
173-
err_res := nssl.ssl_error(sent, s.ssl) ?
197+
err_res := ssl_error(sent, s.ssl) ?
174198
if err_res == .ssl_error_want_read {
175199
for {
176200
ready := @select(s.handle, .read, s.duration) ?
@@ -202,9 +226,9 @@ This is basically a copy of Emily socket implementation of select.
202226
This have to be consolidated into common net lib features
203227
when merging this to V
204228
*/
205-
[typedef]
206-
pub struct C.fd_set {
207-
}
229+
// [typedef]
230+
// pub struct C.fd_set {
231+
// }
208232

209233
// Select waits for an io operation (specified by parameter `test`) to be available
210234
fn @select(handle int, test Select, timeout time.Duration) ?bool {

0 commit comments

Comments
 (0)