Пример #1
0
static int rx_cm_data(SOCKET fd, struct ofi_ctrl_hdr *hdr,
		      int type, struct poll_fd_info *poll_info)
{
	ssize_t ret;

	ret = ofi_recv_socket(fd, hdr,
			      sizeof(*hdr), MSG_WAITALL);
	if (ret != sizeof(*hdr))
		return -FI_EIO;

	if (hdr->type != type)
		return -FI_ECONNREFUSED;

	if (hdr->version != OFI_CTRL_VERSION)
		return -FI_ENOPROTOOPT;

	poll_info->cm_data_sz = ntohs(hdr->seg_size);
	if (poll_info->cm_data_sz) {
		if (poll_info->cm_data_sz > TCPX_MAX_CM_DATA_SIZE)
			return -FI_EINVAL;

		ret = ofi_recv_socket(fd, poll_info->cm_data,
				      poll_info->cm_data_sz, MSG_WAITALL);
		if ((size_t) ret != poll_info->cm_data_sz)
			return -FI_EIO;
	}
	return FI_SUCCESS;
}
Пример #2
0
static void discard_cm_data(SOCKET fd, size_t discard_sz)
{
	char tmp_buf;
	ssize_t ret = 0;
	size_t i;

	for (i = 0; ((i < discard_sz) && (ret > 0)); i++) {
		ret = ofi_recv_socket(fd, &tmp_buf, 1,
				      MSG_WAITALL);
	}
}
Пример #3
0
int tcpx_recv_hdr(SOCKET sock, struct tcpx_rx_detect *rx_detect)
{
	void *rem_buf;
	size_t rem_len;
	ssize_t bytes_recvd;

	rem_buf = (uint8_t *) &rx_detect->hdr + rx_detect->done_len;
	rem_len = sizeof(rx_detect->hdr) - rx_detect->done_len;

	bytes_recvd = ofi_recv_socket(sock, rem_buf, rem_len, 0);
	if (bytes_recvd <= 0)
		return (bytes_recvd)? -ofi_sockerr(): -FI_ENOTCONN;

	rx_detect->done_len += bytes_recvd;
	return (rem_len == bytes_recvd)? FI_SUCCESS : -FI_EAGAIN;
}
Пример #4
0
ssize_t sock_comm_peek(struct sock_conn *conn, void *buf, size_t len)
{
	ssize_t ret;
	ret = ofi_recv_socket(conn->sock_fd, buf, len, MSG_PEEK);
	if (ret == 0) {
		conn->connected = 0;
		SOCK_LOG_DBG("Disconnected\n");
		return ret;
	}

	if (ret < 0) {
		SOCK_LOG_DBG("peek %s\n", strerror(ofi_sockerr()));
		ret = 0;
	}

	if (ret > 0)
		SOCK_LOG_DBG("peek from network: %lu\n", ret);
	return ret;
}
Пример #5
0
static int rx_cm_data(SOCKET fd, struct ofi_ctrl_hdr *hdr,
		      int type, struct tcpx_cm_context *cm_ctx)
{
	ssize_t ret;

	ret = ofi_recv_socket(fd, hdr,
			      sizeof(*hdr), MSG_WAITALL);
	if (ret != sizeof(*hdr))
		return -FI_EIO;

	if (hdr->version != OFI_CTRL_VERSION)
		return -FI_ENOPROTOOPT;

	ret = read_cm_data(fd, cm_ctx, hdr);
	if (hdr->type != type) {
		ret = -FI_ECONNREFUSED;
	}
	return ret;
}
Пример #6
0
static int read_cm_data(SOCKET fd, struct tcpx_cm_context *cm_ctx,
			struct ofi_ctrl_hdr *hdr)
{
	cm_ctx->cm_data_sz = ntohs(hdr->seg_size);
	if (cm_ctx->cm_data_sz) {
		size_t data_sz = MIN(cm_ctx->cm_data_sz,
				     TCPX_MAX_CM_DATA_SIZE);
		ssize_t ret = ofi_recv_socket(fd, cm_ctx->cm_data,
					      data_sz, MSG_WAITALL);
		if ((size_t) ret != data_sz)
			return -FI_EIO;
		cm_ctx->cm_data_sz = data_sz;

		if (OFI_UNLIKELY(cm_ctx->cm_data_sz >
					TCPX_MAX_CM_DATA_SIZE)) {
			discard_cm_data(fd, cm_ctx->cm_data_sz -
					TCPX_MAX_CM_DATA_SIZE);
		}
	}
	return FI_SUCCESS;
}
Пример #7
0
static ssize_t sock_comm_recv_socket(struct sock_conn *conn,
			      void *buf, size_t len)
{
	ssize_t ret;
	ret = ofi_recv_socket(conn->sock_fd, buf, len, 0);
	if (ret == 0) {
		conn->connected = 0;
		SOCK_LOG_DBG("Disconnected: %s:%d\n",
			     inet_ntoa(conn->addr.sin_addr),
			     ntohs(conn->addr.sin_port));
		return ret;
	}

	if (ret < 0) {
		SOCK_LOG_DBG("read %s\n", strerror(ofi_sockerr()));
		ret = 0;
	}

	if (ret > 0)
		SOCK_LOG_DBG("read from network: %lu\n", ret);
	return ret;
}