summary refs log tree commit diff stats
path: root/tests/stdlib/tsystem.nim
Commit message (Expand)AuthorAgeFilesLines
* make more standard libraries work with `nimPreviewSlimSystem` (#20343)ringabout2022-09-271-0/+1
* follow up #19968; add more tests (#20396)ringabout2022-09-201-0/+60
* fixes #19967; reset does not work on set [backport: 1.2] (#19968)ringabout2022-08-231-0/+27
* fixed system.delete (#18507)Andreas Rumpf2021-07-181-4/+4
* Raise IndexDefect when deleting element at out of bounds index (#17821)Heiko Nickerl2021-06-201-1/+31
* fix #17911 rawProc for cpp (#17912)Timothee Cour2021-05-011-0/+46
es for asynchronous sockets. Asyncio should now work well with buffered and unbuffered plain and ssl sockets. Added asyncio' href='/ahoang/Nim/commit/tests/run/tasynciossl.nim?h=devel&id=5310a3044fa4187274e2bfe59de68f394a81c89d'>5310a3044 ^
e80465dac ^
d640fe7af ^
5310a3044 ^


e80465dac ^
5310a3044 ^


e9604b443 ^
5310a3044 ^




e9604b443 ^
5310a3044 ^
526798498 ^
5310a3044 ^








e9604b443 ^
5310a3044 ^








f972b464c ^
5310a3044 ^







f972b464c ^
5310a3044 ^


























e9604b443 ^

5310a3044 ^


2fb5d6292 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

                         
                                                           



                                        

                                   


                  
                                                
                                                                                    


                                                 
     


                      
                                    




                                    
                                  
               
                         








                                   
                                    








                                                                
                              







                                                                
                            


























                                                     

                                                                        


                                                             
              
discard """
  file: "tasynciossl.nim"
  cmd: "nim $target --hints:on --define:ssl $options $file"
  output: "20000"
"""
import sockets, asyncio, strutils, times

var disp {.threadvar.}: PDispatcher
disp = newDispatcher()
var msgCount = 0

when defined(ssl):
  var ctx = newContext(verifyMode = CVerifyNone,
      certFile = "tests/testdata/mycert.pem", keyFile = "tests/testdata/mycert.pem")

  var ctx1 = newContext(verifyMode = CVerifyNone)

const
  swarmSize = 50
  messagesToSend = 100

proc swarmConnect(s: PAsyncSocket) =
  #echo("Connected")
  for i in 1..messagesToSend:
    s.send("Message " & $i & "\c\L")
  s.close()

proc serverRead(s: PAsyncSocket) =
  var line = ""
  assert s.readLine(line)
  if line != "":
    #echo(line)
    if line.startsWith("Message "):
      msgCount.inc()
    else:
      assert(false)
  else:
    s.close()

proc serverAccept(s: PAsyncSocket) =
  var client: PAsyncSocket
  new(client)
  s.accept(client)
  client.handleRead = serverRead
  disp.register(client)

proc launchSwarm(disp: var PDispatcher, port: TPort, count: int,
                 buffered = true, useSSL = false) =
  for i in 1..count:
    var client = asyncSocket()
    when defined(ssl):
      if useSSL:
        ctx1.wrapSocket(client)
    client.handleConnect = swarmConnect
    disp.register(client)
    client.connect("localhost", port)

proc createSwarm(port: TPort, buffered = true, useSSL = false) =
  var server = asyncSocket()
  when defined(ssl):
    if useSSL:
      ctx.wrapSocket(server)
  server.handleAccept = serverAccept
  disp.register(server)
  server.bindAddr(port)
  server.listen()
  disp.launchSwarm(port, swarmSize, buffered, useSSL)

when defined(ssl):
  const serverCount = 4
else:
  const serverCount = 2

createSwarm(TPort(10235))
createSwarm(TPort(10236), false)

when defined(ssl):
  createSwarm(TPort(10237), true, true)
  createSwarm(TPort(10238), false, true)

var startTime = epochTime()
while true:
  if epochTime() - startTime >= 300.0:
    break
  if not disp.poll(): break
  if disp.len == serverCount:
    # Only the servers are left in the dispatcher. All clients finished,
    # we need to therefore break.
    break

assert msgCount == (swarmSize * messagesToSend) * serverCount
echo(msgCount)