⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils_socket.h

📁 Path MPICH-V for MPICH the MPI Implementation
💻 H
字号:
/** @file utils_socket.h defines the basic function to open, read and write a socket */#ifndef _INCLUDE_UTILS_SOCKET_H_#define _INCLUDE_UTILS_SOCKET_H_/* The size of buffers for sockets */#define MAX_BUF_FOR_SOCKET   512*1024/** create a socket with special option * @return a socket number */int _usocket(void);/** synchronous reception * @param sock : socket to read * @param buf : reception buffer * @param size : attempted message size * @param flag : special flag to use in Un_x recv function * @return number of bytes read */int _urecv(int sock, void *buf, int size, int flag);/** synchronous send * @param sock : socket to write * @param buf : message to send * @param size : attempted message size * @param flag : special flag to use in Un_x recv function * @return number of bytes read */int _usend(int sock, void *buf, int size, int flag);int _usyncfio(int (*iofunc)(int, void*, int, int), int sock, void*buf, int size, int flag);int _usyncio(int (*iofunc)(int, void*, int), int sock, void*buf, int size);/** synchronous read on pipe or file * @param fd: file descriptor of pipe or file * @param buf: buffer of reception * @param size: number of bytes to read * @return number of bytes read */int _uread(int sock, void *buf, int size);/** synchronous writing on pipe or file * @param fd: file descriptor of pipe or file * @param buf: buffer to write * @param size: number of bytes to write * @return number of bytes wrote  */int _uwrite(int fd, void *buf, int size);#define _UCREATE_SYNCIO(funcname, iofunc, fdtype, bufftype, sizetype) \int funcname(fdtype fd, bufftype buff, sizetype size) \{ \  int n, nb = 0; \  \  while(nb < size) \  { \    n = iofunc(fd, ((char *)buff)+nb, size-nb); \    if(n <= 0) \    { \      if((n < 0) && ((errno == EINTR) || (errno == EAGAIN))) continue; \      else if (n < 0) \      { \        printe( "IO %d/%d bytes before error", nb, size); \        return -1; \      } \      else \      { \        printe( "Connection closed by peer, read %d/%d bytes", nb, size); \        break; \      }\    } \    nb += n; \  } \  return nb; \}#endif  /* _INCLUDE_UTILS_SOCKET_H_ */

⌨️ 快捷键说明

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