📄 connex~1.cc
字号:
// Larbin// Sebastien Ailleret// 15-11-99 -> 14-01-99#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <sys/socket.h>#include <netinet/in.h>#include <netinet/tcp.h>#include <ctype.h>#include <netdb.h>#include <arpa/inet.h>#include <errno.h>#include <iostream.h>/* make write until everything is written * return 0 on success, 1 otherwise * Don't work on non-blocking fds... */int ecrire (int fd, char *buf) { int pos = 0; int count = strlen(buf); while (pos < count) { int i = write(fd, buf + pos, count-pos); if (i == -1) { if (errno != EINTR) { pos = count + 1; } } else { pos += i; } } return pos != count;}/* make write until everything is written * return 0 on success, 1 otherwise * Don't work on non-blocking fds... */int ecrireBuff (int fd, char *buf, int count) { int pos = 0; while (pos < count) { int i = write(fd, buf + pos, count-pos); if (i == -1) { switch (errno) { case EINTR: break; case EIO: pos = count + 1; cerr << "Problem in ecrireBuff (EIO)\n"; break; default: pos = count + 1; cerr << "Problem in ecrireBuff (" << errno << ")\n"; break; } } else { pos += i; } } return pos != count;}/** Write an int on a fds * (uses ecrire) */int ecrireInt (int fd, int i) { char buf[20]; sprintf(buf, "%d", i); return ecrire(fd, buf);}/** Write an int on a fds * (uses ecrire) */int ecrireLong (int fd, long i) { char buf[30]; sprintf(buf, "%ld", i); return ecrire(fd, buf);}/* Write a char on a fds * return 0 on success, 1 otherwise * Don't work on non-blocking fds... */int ecrireChar (int fd, char c) { int pos = 0; while (pos < 1) { int i = write(fd, &c, 1); if (i == -1) { if (errno != EINTR) { pos = 2; } } else { pos += i; } } return pos != 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -