connexion在法语中是连线的意思,在global.h中定义了connexion结构体。而connexion.cc和connexio.h则主要是处理文件的写入的问题,主要利用的是write函数这个系统调用来完成的。他不是普通的write,因为他对里面出现的异常做了很好的处理。其主要用于block的文件的写入。
文件中,有一堆ecrire函数,主要是对char * 的字符串的写入和对int ,long和不同格式的字符的写入。ecrire在法语中是写入的意思。其中值得学习的地方是:
1.核心函数ecrire:
/* 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;
}
将buf中的字符写入文件fd。因为write不能保证完全写入buf中的内容,而它的返回则刚好是实际写