struct utcp_connection *c;
int dir = 3;
bool running = true;
+double dropin;
+double dropout;
int do_recv(struct utcp_connection *c, const void *data, size_t len) {
if(!data || !len) {
int do_send(struct utcp *utcp, const void *data, size_t len) {
int s = *(int *)utcp->priv;
- return send(s, data, len, MSG_DONTWAIT);
+ if(drand48() >= dropout)
+ return send(s, data, len, MSG_DONTWAIT);
+ else
+ return 0;
}
int main(int argc, char *argv[]) {
srand(time(NULL));
+ srand48(time(NULL));
if(argc < 2 || argc > 3)
return 1;
bool server = argc == 2;
bool connected = false;
+ dropin = atof(getenv("DROPIN") ?: "0");
+ dropout = atof(getenv("DROPOUT") ?: "0");
+
struct addrinfo *ai;
struct addrinfo hint = {
.ai_flags = server ? AI_PASSIVE : 0,
if(!connected)
if(!connect(s, (struct sockaddr *)&ss, sl))
connected = true;
- utcp_recv(u, buf, len);
+ if(drand48() >= dropin)
+ utcp_recv(u, buf, len);
}
timeout = utcp_timeout(u);