socket_set_nonblocking(bool nonblocking)
{
	if (MyProcPort == NULL)
		ereport(ERROR,
				(errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
				 errmsg("there is no client connection")));

	if (MyProcPort->noblock == nonblocking)
		return;

#ifdef WIN32
	pgwin32_noblock = nonblocking ? 1 : 0;
#else

	/*
	 * Use COMMERROR on failure, because ERROR would try to send the error to
	 * the client, which might require changing the mode again, leading to
	 * infinite recursion.
	 */
	if (nonblocking)
	{
		if (!pg_set_noblock(MyProcPort->sock))
			ereport(COMMERROR,
					(errmsg("could not set socket to nonblocking mode: %m")));
	}
	else
	{
		if (!pg_set_block(MyProcPort->sock))
			ereport(COMMERROR,
					(errmsg("could not set socket to blocking mode: %m")));
	}
#endif
	MyProcPort->noblock = nonblocking;
}
socket_set_nonblocking(bool nonblocking)
{
	if (MyProcPort == NULL)
		ereport(ERROR,
				(errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
				 errmsg("there is no client connection")));

	if (MyProcPort->noblock == nonblocking)
		return;

#ifdef WIN32
	pgwin32_noblock = nonblocking ? 1 : 0;
#else

	 
	if (nonblocking)
	{
		if (!pg_set_noblock(MyProcPort->sock))
			ereport(COMMERROR,
					(errmsg("could not set socket to nonblocking mode: %m")));
	}
	else
	{
		if (!pg_set_block(MyProcPort->sock))
			ereport(COMMERROR,
					(errmsg("could not set socket to blocking mode: %m")));
	}
#endif
	MyProcPort->noblock = nonblocking;
}