MCPcopy Create free account
hub / github.com/apache/singa / main

Function main

test/singa/test_ep.cc:38–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36
37using namespace singa;
38int main(int argc, char **argv) {
39 char *md = new char[SIZE];
40 char *payload = new char[SIZE];
41
42 const char *host = "localhost";
43 int port = PORT;
44
45 for (int i = 1; i < argc; ++i) {
46 if (strcmp(argv[i], "-p") == 0)
47 port = atoi(argv[++i]);
48 else if (strcmp(argv[i], "-h") == 0)
49 host = argv[++i];
50 else
51 fprintf(stderr, "Invalid option %s\n", argv[i]);
52 }
53
54 memset(md, 'a', SIZE);
55 memset(payload, 'b', SIZE);
56
57 NetworkThread *t = new NetworkThread(port);
58
59 EndPointFactory *epf = t->epf_;
60
61 // sleep
62 sleep(3);
63
64 EndPoint *ep = epf->getEp(host);
65
66 Message *m[ITER];
67 for (int i = 0; i < ITER; ++i) {
68 m[i] = new Message();
69 m[i]->setMetadata(md, SIZE);
70 m[i]->setPayload(payload, SIZE);
71 }
72
73 while (1) {
74 for (int i = 0; i < ITER; ++i) {
75 if (ep->send(m[i]) < 0) return 1;
76 delete m[i];
77 }
78
79 for (int i = 0; i < ITER; ++i) {
80 m[i] = ep->recv();
81 if (!m[i]) return 1;
82 char *p;
83 CHECK_EQ(m[i]->getMetadata((void **)&p), SIZE);
84 CHECK_EQ(0, strncmp(p, md, SIZE));
85 CHECK_EQ(m[i]->getPayload((void **)&p), SIZE);
86 CHECK_EQ(0, strncmp(p, payload, SIZE));
87 }
88 }
89
90 // while(ep && cnt++ <= 5 && ep->send(m) > 0 ) {
91
92 // LOG(INFO) << "Send a " << m->getSize() << " bytes message";
93
94 // Message* m1 = ep->recv();
95

Callers

nothing calls this directly

Calls 7

getEpMethod · 0.80
setMetadataMethod · 0.80
setPayloadMethod · 0.80
sendMethod · 0.80
recvMethod · 0.80
getMetadataMethod · 0.80
getPayloadMethod · 0.80

Tested by

no test coverage detected