CTEST2(tube, tube_data) { tube *t; uint8_t udata[] = "SPUD_makeUBES_FUN"; struct sockaddr_storage remoteAddr; ASSERT_TRUE( ls_sockaddr_get_remote_ip_addr("127.0.0.1", "1402", (struct sockaddr*)&remoteAddr, sizeof(remoteAddr), &data->err)); ASSERT_TRUE( tube_manager_open_tube(data->mgr, (const struct sockaddr*)&remoteAddr, &t, &data->err)); ASSERT_TRUE( tube_data(t, udata, 17, &data->err)); ASSERT_TRUE( tube_data(t, NULL, 0, &data->err)); tube_manager_remove(data->mgr, t); ASSERT_EQUAL(tube_manager_size(data->mgr), 0); }
static void sendData(ls_timer* tim) { unsigned char buf[1024]; int i; ls_err err; UNUSED_PARAM(tim); config.numSentPkts++; for (i = 0; i < 1; i++) { int len = (numChar * i); /* TODO: parse this. */ memcpy(buf + len, s1 + (config.numSentPkts % numChar) + (numChar * i), numChar); } if ( !tube_data(config.t, buf, strlen(s1), &err) ) { LS_LOG_ERR(err, "tube_data"); } if ( !tube_manager_schedule_ms(mgr, 50, sendData, NULL, NULL, &err) ) { LS_LOG_ERR(err, "tube_manager_schedule_ms"); return; } }
static int markov() { struct timespec timer; struct timespec remaining; tube* t; ls_err err; int i; int* iptr; timer.tv_sec = 0; while ( tube_manager_running(mgr) ) { timer.tv_nsec = gauss(50000000, 10000000); nanosleep(&timer, &remaining); i = random() % NUM_TUBES; t = tubes[i]; if (!t) { if ( !tube_create(&t, &err) ) { LS_LOG_ERR(err, "tube_create"); return 1; } tubes[i] = t; iptr = malloc( sizeof(*iptr) ); *iptr = i; tube_set_data(t, iptr); } switch ( tube_get_state(t) ) { case TS_START: ls_log(LS_LOG_ERROR, "invalid tube state"); return 1; case TS_UNKNOWN: if ( !tube_manager_open_tube(mgr, (const struct sockaddr*)&remoteAddr, &t, &err) ) { LS_LOG_ERR(err, "tube_manager_open_tube"); return 1; } break; case TS_OPENING: /* keep waiting by the mailbox, Charlie Brown */ break; case TS_RUNNING: /* .1% chance of close */ if ( (random() % 10000) < 10 ) { if ( !tube_close(t, &err) ) { LS_LOG_ERR(err, "tube_close"); return 1; } } else { /* TODO: put something intersting in the buffer */ if ( !tube_data(t, data, random() % sizeof(data), &err) ) { LS_LOG_ERR(err, "tube_data"); return 1; } } case TS_RESUMING: /* can't get here yet */ break; } } return 0; }