| 1 | // vtest build: !windows && present_openssl? |
| 2 | import net.websocket as ws |
| 3 | |
| 4 | pub type RawMessage = ws.Message |
| 5 | |
| 6 | pub struct WsTransport { |
| 7 | pub mut: |
| 8 | ws ws.Client |
| 9 | } |
| 10 | |
| 11 | struct WsClient { |
| 12 | pub mut: |
| 13 | transport Transport |
| 14 | } |
| 15 | |
| 16 | pub interface Transport { |
| 17 | send() |
| 18 | wait() |
| 19 | } |
| 20 | |
| 21 | fn (wst WsTransport) send() { |
| 22 | println('send is called') |
| 23 | } |
| 24 | |
| 25 | fn (wst WsTransport) wait() { |
| 26 | println('wait is called') |
| 27 | } |
| 28 | |
| 29 | pub fn new_ws_client(transport Transport) !WsClient { |
| 30 | return WsClient{ |
| 31 | transport: transport |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | fn server() ! { |
| 36 | mut s := ws.new_server(.ip6, 8081, '/') |
| 37 | |
| 38 | s.on_connect(fn (mut s ws.ServerClient) !bool { |
| 39 | if s.resource_name != '/' { |
| 40 | return false |
| 41 | } |
| 42 | println('Client has connected...') |
| 43 | return true |
| 44 | })! |
| 45 | |
| 46 | s.on_message(fn (mut ws_ ws.Client, msg &RawMessage) ! { |
| 47 | mut transport := WsTransport{} |
| 48 | mut ws_client := new_ws_client(transport)! |
| 49 | _ := ws_client |
| 50 | }) |
| 51 | |
| 52 | s.on_close(fn (mut ws_ ws.Client, code int, reason string) ! { |
| 53 | println('client (${ws_.id}) closed connection') |
| 54 | }) |
| 55 | |
| 56 | s.listen() or { println('error on server listen: ${err}') } |
| 57 | |
| 58 | unsafe { |
| 59 | s.free() |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | fn abc() ! { |
| 64 | server()! |
| 65 | } |
| 66 | |
| 67 | fn test_compilation_of_the_example_code_in_issue_15839() { |
| 68 | assert true |
| 69 | } |
| 70 | |