int task_main(void* args) { int i; int eid; int size; int rts; char* ubuf; if (argc < 4) { printf("usage: thr_sender <connect-to> <msg-size> <roundtrips>\n"); return 0; } size = atoi(argv[2]); rts = atoi(argv[3]); BUG_ON((eid = sp_endpoint(SP_REQREP, SP_REQ)) < 0); BUG_ON(sp_connect(eid, argv[1]) < 0); BUG_ON(sp_send(eid, ualloc(size)) != 0); for (i = 0; i < rts; i++) { BUG_ON(sp_send(eid, ualloc(size)) != 0); } BUG_ON(sp_recv(eid, &ubuf) != 0); ufree(ubuf); sp_close(eid); return 0; }
int main(int argc, char** argv) { int i; int eid; int count; int size; char* ubuf; int thr; double mbs; uint64_t st, lt; if (argc < 3) { printf("usage: thr_recver <bind-to> <msg-count>\n"); return 0; } count = atoi(argv[2]); BUG_ON((eid = sp_endpoint(SP_REQREP, SP_REP)) < 0); BUG_ON(sp_listen(eid, argv[1]) < 0); BUG_ON(sp_recv(eid, &ubuf) != 0); size = 0; st = gettimeofms(); while (count > 0) { BUG_ON(sp_recv(eid, &ubuf) != 0); count--; size += usize(ubuf); if (count) { ufree(ubuf); } else { BUG_ON(sp_send(eid, ubuf) != 0); } } lt = gettimeofms(); thr = atoi(argv[2]) * 1000 / (lt - st); mbs = (double)(size * 8 / (lt - st)) / 1024; printf("message size: %d [B]\n", size); printf("throughput: %d [msg/s]\n", thr); printf("throughput: %.3f [Mb/s]\n", mbs); sp_close(eid); return 0; }
static VALUE rb_sp_recv (VALUE self, VALUE eid) { int _eid = FIX2INT (eid); int rc; char *ubuf = 0; VALUE msg; if ((rc = sp_recv (_eid, &ubuf))) return Qnil; msg = rb_str_new (ubuf, ubuf_len (ubuf)); rb_iv_set (msg, "@hdr", Data_Wrap_Struct (0, 0, ubuf_free, ubuf)); return msg; }
void worker (void *arg) { int rc; int s; char buf [3]; s = sp_socket (AF_SP, SP_PAIR); errno_assert (s != -1); rc = sp_recv (s, buf, sizeof (buf), 0); sp_assert (rc == -1 && sp_errno () == ETERM); rc = sp_close (s); errno_assert (rc == 0); }
int main (int argc, char **argv) { int i; int eid; char *ubuf; if (argc < 2) { printf ("usage: lat_recver <bind-to>\n"); return 0; } BUG_ON ((eid = sp_endpoint (SP_REQREP, SP_REP)) < 0); BUG_ON (sp_listen (eid, argv[1]) < 0); while (1) { BUG_ON (sp_recv (eid, &ubuf) != 0); BUG_ON (sp_send (eid, ubuf)); } sp_close (eid); return 0; }
int main () { int rc; int rep; int req1; int req2; int resend_ivl; char buf [7]; /* Test req/rep with raw socket types. */ rc = sp_init (); errno_assert (rc == 0); rep = sp_socket (AF_SP_RAW, SP_REP); errno_assert (rep != -1); rc = sp_bind (rep, "inproc://a"); errno_assert (rc >= 0); req1 = sp_socket (AF_SP_RAW, SP_REQ); errno_assert (req1 != -1); rc = sp_connect (req1, "inproc://a"); errno_assert (rc >= 0); req2 = sp_socket (AF_SP_RAW, SP_REQ); errno_assert (req2 != -1); rc = sp_connect (req2, "inproc://a"); errno_assert (rc >= 0); rc = sp_send (req2, "ABC", 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (rep, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 7); rc = sp_send (rep, buf, 7, 0); errno_assert (rc >= 0); sp_assert (rc == 7); rc = sp_recv (req2, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_send (req1, "ABC", 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (rep, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 7); rc = sp_send (rep, buf, 7, 0); errno_assert (rc >= 0); sp_assert (rc == 7); rc = sp_recv (req1, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_close (rep); errno_assert (rc == 0); rc = sp_close (req1); errno_assert (rc == 0); rc = sp_close (req2); errno_assert (rc == 0); rc = sp_term (); errno_assert (rc == 0); /* Test req/rep with full socket types. */ rc = sp_init (); errno_assert (rc == 0); rep = sp_socket (AF_SP, SP_REP); errno_assert (rep != -1); rc = sp_bind (rep, "inproc://a"); errno_assert (rc >= 0); req1 = sp_socket (AF_SP, SP_REQ); errno_assert (req1 != -1); rc = sp_connect (req1, "inproc://a"); errno_assert (rc >= 0); req2 = sp_socket (AF_SP, SP_REQ); errno_assert (req2 != -1); rc = sp_connect (req2, "inproc://a"); errno_assert (rc >= 0); rc = sp_send (rep, "ABC", 3, 0); sp_assert (rc == -1 && sp_errno () == EFSM); rc = sp_recv (req1, buf, sizeof (buf), 0); sp_assert (rc == -1 && sp_errno () == EFSM); rc = sp_send (req2, "ABC", 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (rep, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_send (rep, buf, 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (req2, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_send (req1, "ABC", 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (rep, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_send (rep, buf, 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (req1, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_close (rep); errno_assert (rc == 0); rc = sp_close (req1); errno_assert (rc == 0); rc = sp_close (req2); errno_assert (rc == 0); rc = sp_term (); errno_assert (rc == 0); /* Test re-sending of the request. */ rc = sp_init (); errno_assert (rc == 0); rep = sp_socket (AF_SP, SP_REP); errno_assert (rep != -1); rc = sp_bind (rep, "inproc://a"); errno_assert (rc >= 0); req1 = sp_socket (AF_SP, SP_REQ); errno_assert (req1 != -1); rc = sp_connect (req1, "inproc://a"); errno_assert (rc >= 0); resend_ivl = 100; rc = sp_setsockopt (req1, SP_REQ, SP_RESEND_IVL, &resend_ivl, sizeof (resend_ivl)); errno_assert (rc == 0); rc = sp_send (req1, "ABC", 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (rep, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (rep, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_close (req1); errno_assert (rc == 0); rc = sp_close (rep); errno_assert (rc == 0); rc = sp_term (); errno_assert (rc == 0); return 0; }