代码拉取完成,页面将自动刷新
#include "common.h"
ssize_t Write(int fd, const void *buf, size_t nbyte)
{
if(buf == NULL)
return -1;
const char *tmp = buf;
ssize_t total = 0;
while(nbyte > 0)
{
ssize_t n = write(fd, tmp, nbyte);
if(n == -1)
{
perror("write() error");
return -1;
}
nbyte -= n;
tmp += n;
total += n;
}
return total;
}
ssize_t Read(int fd, void *buf, size_t nbyte)
{
if(buf == NULL)
return -1;
ssize_t n = read(fd, buf, nbyte);
if(n == -1)
{
perror("read() error");
return -1;
}
return n;
}
int Bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
int ret = bind(sockfd, addr, addrlen);
if(ret == -1)
{
perror("bind() error");
}
return ret;
}
int Listen(int sockfd, int backlog)
{
int ret = listen(sockfd, backlog);
if(ret == -1)
{
perror("listen() error");
}
return ret;
}
int Accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
{
int ret = accept(sockfd, addr, addrlen);
if(ret == -1)
{
perror("accept() error");
}
return ret;
}
int Connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
{
int connfd = connect(sockfd, addr, addrlen);
if(connfd == -1)
{
perror("connect() error");
}
return connfd;
}
int Socket(int domain, int type, int protocol)
{
int sockfd = socket(domain, type, protocol);
if(sockfd == -1)
{
perror("socket() error");
}
return sockfd;
}
int Setsockopt(int sockfd, int level, int optname,
const void *optval, socklen_t optlen)
{
int ret = setsockopt(sockfd, level, optname, optval, optlen);
if(ret == -1)
{
perror("setsockopt() error");
}
return ret;
}
int Select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout)
{
int ret = select(nfds, readfds, writefds, exceptfds, timeout);
if(ret == 0)
{
printf("select() timeout.\n");
}
else if(ret == -1)
{
perror("select() failed");
}
return ret;
}
int Poll(struct pollfd *fds, nfds_t nfds, int timeout)
{
int n = poll(fds, nfds, timeout);
if(n == -1)
{
perror("poll() failed");
}
return n;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。