connex~1.cc
来自「一百个病毒的源代码 包括熊猫烧香等 极其具有研究价值」· CC 代码 · 共 105 行
CC
105 行
// 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 + =
减小字号Ctrl + -
显示快捷键?