MCPcopy Create free account
hub / github.com/dmtcp/dmtcp / main

Function main

test/frisbee.cpp:21–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19 const char *hostname);
20
21int
22main(int argc, char **argv)
23{
24 if (argc != 4 && argc != 5) {
25 printf("usage: player listen-port connect-host connect-port [starter]\n");
26 return -1;
27 }
28
29 int listenSock = socket(AF_INET, SOCK_STREAM, 0);
30 int connectSock = socket(AF_INET, SOCK_STREAM, 0);
31 int acceptSock = -1;
32 assert(listenSock > 0 && connectSock > 0);
33
34 int listenPort = atoi(argv[1]);
35 hostent *connectHost = gethostbyname(argv[2]);
36 int connectPort = atoi(argv[3]);
37 assert(listenPort > 0);
38 assert(connectHost != NULL);
39 assert(connectPort > 0);
40
41 bool isStarterNode = (argc == 5);
42
43 // bind listen socket
44 {
45 sockaddr_in listenAddy;
46 memset(&listenAddy, 0, sizeof(listenAddy));
47 listenAddy.sin_family = AF_INET;
48 listenAddy.sin_addr.s_addr = INADDR_ANY;
49 listenAddy.sin_port = htons(listenPort);
50
51 assert(bind(listenSock, (sockaddr *)&listenAddy, sizeof(listenAddy)) >= 0);
52
53 assert(listen(listenSock, 5) >= 0);
54 }
55
56 {
57 // std::cout << "starter node? [y/n] ";
58 // std::string c;
59 // std::cin >> c;
60 // if ( c[0]=='y' || c[0]=='Y' ) isStarterNode = true;
61 }
62
63 if (!isStarterNode) {
64 std::cout << "accepting..." << std::endl;
65 doAccept(acceptSock, listenSock);
66 std::cout << "connecting..." << std::endl;
67 doConnect(connectSock, connectHost, connectPort, argv[2]);
68 } else {
69 std::cout << "connecting..." << std::endl;
70 doConnect(connectSock, connectHost, connectPort, argv[2]);
71 std::cout << "accepting..." << std::endl;
72 doAccept(acceptSock, listenSock);
73 }
74 std::cout << "ready" << std::endl;
75
76 for (;;) {
77 std::cout << "throw [a-z] or catch [C]?";
78 std::cout.flush();

Callers

nothing calls this directly

Calls 7

gethostbynameFunction · 0.85
memsetFunction · 0.85
doAcceptFunction · 0.85
doConnectFunction · 0.85
socketFunction · 0.50
bindFunction · 0.50
listenFunction · 0.50

Tested by

no test coverage detected