send_blocking.cpp

来自「MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程」· C++ 代码 · 共 39 行

CPP
39
字号
#include "sockets.h"// Function name	: SendBlocking// Description	    : // Return type		: int // Argument         : SOCKET sock// Argument         : char *buffer// Argument         : int length// Argument         : int flagsint SendBlocking(SOCKET sock, char *buffer, int length, int flags){	WSABUF buf;	int error;	DWORD num_sent;	buf.buf = buffer;	buf.len = length;	while (WSASend(sock, &buf, 1, &num_sent, flags, NULL, NULL) == SOCKET_ERROR)	{		error = WSAGetLastError();		if (error == WSAEWOULDBLOCK)		{			continue;		}		if (error == WSAENOBUFS)		{			// If there is no buffer space available then split the buffer in half and send each piece separately.			SendBlocking(sock, buf.buf, buf.len/2, flags);			SendBlocking(sock, buf.buf+(buf.len/2), buf.len - (buf.len/2), flags);			return length;		}		WSASetLastError(error);		return SOCKET_ERROR;	}	return length;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?