/*---------------------------------------------------------------------------*/ static int on_message_delivered(struct xio_session *session, struct xio_msg *msg, int last_in_rxq, void *cb_user_context) { struct ow_test_params *ow_params = (struct ow_test_params *)cb_user_context; struct xio_msg *new_msg; process_tx_message(ow_params, msg); ow_params->ndelivered++; /* can be safely returned to pool */ msg_pool_put(ow_params->pool, msg); if (ow_params->finite_run) { if (ow_params->ndelivered == ow_params->disconnect_nr) { xio_disconnect(ow_params->conn); return 0; } if (ow_params->nsent == ow_params->disconnect_nr) return 0; } /* peek message from the pool */ new_msg = msg_pool_get(ow_params->pool); if (new_msg == NULL) { printf("pool is empty\n"); return 0; } /* assign buffers to the message */ msg_write(&ow_params->msg_params, new_msg, test_config.hdr_len, 1, test_config.data_len); /* * ask for receipt since we need to put the message back * to pool */ new_msg->flags = XIO_MSG_FLAG_REQUEST_READ_RECEIPT; /* send it */ if (xio_send_msg(ow_params->conn, new_msg) == -1) { if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_msg " \ "failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(ow_params->pool, new_msg); xio_assert(0); } ow_params->nsent++; return 0; }
/*---------------------------------------------------------------------------*/ static int on_new_session(struct xio_session *session, struct xio_new_session_req *req, void *cb_user_context) { int i = 0; struct ow_test_params *ow_params = cb_user_context; struct xio_msg *msg; printf("**** [%p] on_new_session :%s:%d\n", session, get_ip((struct sockaddr *)&req->src_addr), get_port((struct sockaddr *)&req->src_addr)); xio_accept(session, NULL, 0, NULL, 0); if (ow_params->connection == NULL) ow_params->connection = xio_get_connection(session, ow_params->ctx); for (i = 0; i < MAX_OUTSTANDING_REQS; i++) { /* pick message from the pool */ msg = msg_pool_get(ow_params->pool); if (msg == NULL) break; /* assign buffers to the message */ msg_write(&ow_params->msg_params, msg, NULL, test_config.hdr_len, NULL, test_config.data_len); /* ask for read receipt since the message needed to be * recycled to the pool */ msg->flags = XIO_MSG_FLAG_REQUEST_READ_RECEIPT; /* send the message */ if (xio_send_msg(ow_params->connection, msg) == -1) { printf("**** sent %d messages\n", i); if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_msg " \ "failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(ow_params->pool, msg); return 0; } ow_params->nsent++; } return 0; }
/*---------------------------------------------------------------------------*/ static int on_message_delivered(struct xio_session *session, struct xio_msg *msg, int more_in_batch, void *cb_user_context) { struct xio_msg *new_msg; struct ow_test_params *ow_params = cb_user_context; ow_params->ndelivered++; /* can be safely freed */ msg_pool_put(ow_params->pool, msg); #if TEST_DISCONNECT if (ow_params->ndelivered == DISCONNECT_NR) { xio_disconnect(ow_params->connection); return 0; } if (ow_params->nsent == DISCONNECT_NR) return 0; #endif /* peek new message from the pool */ new_msg = msg_pool_get(ow_params->pool); new_msg->more_in_batch = 0; /* fill response */ msg_write(&ow_params->msg_params, new_msg, NULL, test_config.hdr_len, NULL, test_config.data_len); new_msg->flags = XIO_MSG_FLAG_REQUEST_READ_RECEIPT; if (xio_send_msg(ow_params->connection, new_msg) == -1) { printf("**** [%p] Error - xio_send_msg failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(ow_params->pool, new_msg); } ow_params->nsent++; return 0; }
/*---------------------------------------------------------------------------*/ static int on_message_delivered(struct xio_session *session, struct xio_msg *msg, int more_in_batch, void *cb_user_context) { struct xio_msg *new_msg; process_tx_message(msg); /* can be safely returned to pool */ msg_pool_put(pool, msg); /* peek message from the pool */ new_msg = msg_pool_get(pool); if (new_msg == NULL) { printf("pool is empty\n"); return 0; } /* assign buffers to the message */ msg_write(new_msg, NULL, test_config.hdr_len, NULL, test_config.data_len); /* * ask for receipt since we need to put the message back * to pool */ new_msg->flags = XIO_MSG_FLAG_REQUEST_READ_RECEIPT; /* send it */ if (xio_send_msg(conn, new_msg) == -1) { if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_msg " \ "failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(pool, new_msg); return 0; } return 0; }
/*---------------------------------------------------------------------------*/ static int on_msg_send_complete(struct xio_session *session, struct xio_msg *msg, void *cb_user_context) { struct test_params *test_params = cb_user_context; process_message(test_params, msg); test_params->ncomp++; /* can be safely freed */ msg_pool_put(test_params->pool, msg); if (test_params->finite_run) { if ((test_params->ncomp+test_params->ndelivered) > test_params->disconnect_nr) return 0; if ((test_params->ncomp + test_params->ndelivered) == test_params->disconnect_nr) { xio_disconnect(test_params->connection); return 0; } } if (test_params->closed) return 0; /* peek message from the pool */ msg = msg_pool_get(test_params->pool); if (msg == NULL) { printf("pool is empty\n"); return 0; } /* reset message */ msg->in.header.iov_base = NULL; msg->in.header.iov_len = 0; msg->in.data_iov.nents = 0; msg->more_in_batch = 0; /* assign buffers to the message */ msg_write(&test_params->msg_params, msg, test_config.hdr_len, 1, test_config.data_len); /* try to send it */ if (test_params->ask_for_receipt) msg->flags = XIO_MSG_FLAG_REQUEST_READ_RECEIPT; else msg->flags = 0; if (xio_send_msg(test_params->connection, msg) == -1) { if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_request " \ "failed %s\n", session, xio_strerror(xio_errno())); msg_pool_put(test_params->pool, msg); xio_assert(0); } test_params->nsent++; return 0; }