5 Star 21 Fork 13

翠微薛之谦/ARM_智能车库管理系统__LinuxC

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
wrap.c 2.01 KB
一键复制 编辑 原始数据 按行查看 历史
翠微薛之谦 提交于 2019-01-18 16:41 . one
#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;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/joker_cuiwei/arm_carparking_c.git
[email protected]:joker_cuiwei/arm_carparking_c.git
joker_cuiwei
arm_carparking_c
ARM_智能车库管理系统__LinuxC
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385