summary refs log tree commit diff stats
path: root/tests/tuples/twrongtupleaccess.nim
Commit message (Expand)AuthorAgeFilesLines
* require errormsg to be specified before file.Arne Döring2018-12-111-2/+1
* s/procedure/routine/ in tests.Dominik Picheta2015-06-051-1/+1
* Got rid of errUndeclaredProcedureField.Dominik Picheta2015-06-041-1/+1
* Fixes #2584Dominik Picheta2015-06-041-1/+1
* new tester; all tests categorizedAraq2014-01-131-0/+10
4667552badb3e984dd7086b634'>^
7b816a9fa ^

74fdd5c2e ^
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




                                                                            









                                                                                     




                                                                     

                                                                  
                                                       

    
                                                    
'>
d310b01db ^
cac39b27c ^
be991ed41 ^
2ce07042f ^
d310b01db ^
00b6a1448 ^

cac39b27c ^
d310b01db ^
cac39b27c ^
d310b01db ^
cac39b27c ^
6a38d3623 ^
cac39b27c ^







d310b01db ^
be991ed41 ^
2ce9f1c77 ^
56f11e2c9 ^
2ce9f1c77 ^



5a582a0d9 ^
2ce9f1c77 ^
56f11e2c9 ^


e80465dac ^
56f11e2c9 ^
cac39b27c ^
a8771b305 ^
cac39b27c ^
cdcdab49b ^

cac39b27c ^
d310b01db ^
cac39b27c ^



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

                         

                
                                                      
 







                      
                                               
                                
                                                
 
                                         
                           
                                     
 
                                          

                            
 
                                               
             
                                     
                  
                         







                                     
                                          
                                     
        
                         



                                            
                                       
                                            


                                                                    
 
                                      
             
                                                 
 

                                     
           
        



                                             
discard """
  file: "tasyncawait.nim"
  output: "5000"
"""
import asyncdispatch, nativesockets, net, strutils, os

var msgCount = 0

const
  swarmSize = 50
  messagesToSend = 100

var clientCount = 0

proc sendMessages(client: TAsyncFD) {.async.} =
  for i in 0 .. <messagesToSend:
    await send(client, "Message " & $i & "\c\L")

proc launchSwarm(port: TPort) {.async.} =
  for i in 0 .. <swarmSize:
    var sock = newAsyncNativeSocket()

    await connect(sock, "localhost", port)
    await sendMessages(sock)
    closeSocket(sock)

proc readMessages(client: TAsyncFD) {.async.} =
  while true:
    var line = await recvLine(client)
    if line == "":
      closeSocket(client)
      clientCount.inc
      break
    else:
      if line.startswith("Message "):
        msgCount.inc
      else:
        doAssert false

proc createServer(port: TPort) {.async.} =
  var server = newAsyncNativeSocket()
  block:
    var name: Sockaddr_in
    when defined(windows):
      name.sin_family = toInt(AF_INET).int16
    else:
      name.sin_family = toInt(AF_INET)
    name.sin_port = htons(uint16(port))
    name.sin_addr.s_addr = htonl(INADDR_ANY)
    if bindAddr(server.SocketHandle, cast[ptr SockAddr](addr(name)),
                sizeof(name).Socklen) < 0'i32:
      raiseOSError(osLastError())

  discard server.SocketHandle.listen()
  while true:
    asyncCheck readMessages(await accept(server))

asyncCheck createServer(TPort(10335))
asyncCheck launchSwarm(TPort(10335))
while true:
  poll()
  if clientCount == swarmSize: break

assert msgCount == swarmSize * messagesToSend
echo msgCount