errno

C库函数

江枫思渺然 提交于 2019-11-28 07:47:13
1. errno 有几点需要注意: ① errno是全局变量,使用前应该先清零 ② errno是线程安全的 ③ errno不适用于获取文件流错误,文件流错误请使用 ④ errno可以自定义错误处理函数,可以展开为一个函数调用返回,所以可以是左值 if(ferror(fp)) clearerr(fp); fclose(fp); 参考:http://c.biancheng.net/c/errno/ https://www.cnblogs.com/yanenquan/p/3776712.html 来源: https://www.cnblogs.com/abnk/p/11399912.html

Is there a way to use errno safely in a multi-threaded application? [duplicate]

偶尔善良 提交于 2019-11-28 07:12:12
This question already has an answer here: Is errno thread-safe? 8 answers If you are writing a multi-threaded application that uses system/library calls that make use of errno to indicate the error type, is there a safe way to use errno? If not, is there some other way to indicate the type of error that occurred rather than just that an error has occurred? If your standard library is multithread aware, then it probably has a #define that changes errno into a function call that returns a thread-local error return value. However, to use this you generally must include <errno.h> , rather than

Unable to run Protractor - ECONNREFUSED connect ECONNREFUSED

房东的猫 提交于 2019-11-28 04:54:18
I'm trying to learn AngularJS. As part of this, I want to learn to use end-to-end testing. Currently, I have a directory structure like this: node_modules .bin ... protractor ... node_modules .bin adam-zip glob minijasminenode optimist saucelabs selenium-webdriver protractor config.js src tests test.e2e.js My config.js file looks like the following: exports.config = { seleniumAddress: 'http://localhost:4444/wd/hub', capabilities: { 'browserName': 'chrome' }, specs: [ '../src/tests/test.e2e.js' ], jasmineNodeOpts: { showColors: true, defaultTimeoutInterval: 30000 } }; test.e2e.js looks like the

windows--OSError: [Errno 22] Invalid argument: '\\u202aE:/desk/Desktop/test.txt' 读取文件的坑

不想你离开。 提交于 2019-11-28 01:22:37
准备打开文件时,报了如下错误: 在路径中出现了这个Unicode 202a字符,导致了这个错误。 这玩意是哪里来的? 复制windows文件属性的时候复制下图中的路径而来的。 解释: 这个字符的含义是left to right,也就是从左到右的阅读顺序, 在写代码的时候显示不出来,但是在命令行中可以显示出来。 感受一下,复制下面的这一句话,分别放在命令行和Pycharm中 with open(r'‪E:/desk/Desktop/test.txt', 'r') as file: 解决方案: 把 鼠标放到E后面,然后backspace向左删除一个字符 ,会发现显示上没有发生变化,但是控制字符已经被删除了。 来源: https://www.cnblogs.com/liangmingshen/p/11385584.html

python异常报错详解

空扰寡人 提交于 2019-11-28 01:17:20
异常BaseException 所有内置异常的基类。它不是直接由用户定义的类继承(为此使用Exception)。如果 str()或者unicode()是在这个类的一个实例上被调用,返回实例的参数表示形式,或者当没有参数时,返回空字符串。 新版本2.5。 args 给异常构造函数的元组元组。一些内置异常(如IOError)期望一定数量的参数,并为此元组的元素分配特殊含义,而其他异常通常仅使用单个字符串给出错误消息。 异常Exception 所有内置的非系统退出的异常都是从这个类派生出来的。所有用户定义的异常也应该从此类派生。 更改版本2.5:更改为继承BaseException。 异常StandardError 该基类除了所有内置例外StopIteration, GeneratorExit,KeyboardInterrupt和SystemExit。 StandardError本身源于Exception。 异常ArithmeticError 对于那些内置异常的基类时引发的各种算术错误:OverflowError,ZeroDivisionError, FloatingPointError。 异常BufferError 当无法执行缓冲区相关操作时引发。 异常LookupError 当映射或序列上使用的键或索引无效时引发异常的基类:IndexError,KeyError

零拷贝Zero copy-linux and java

左心房为你撑大大i 提交于 2019-11-28 00:10:15
背景-几种拷贝方式 方式1:Copying in Two Sample System Calls read(file, tmp_buf, len); write(socket, tmp_buf, len); 首先,调用read时,文件A copy到了kernel模式; 之后,CPU控制将kernel模式数据copy到user模式下; 调用write时,先将user模式下的内容copy到kernel模式下的socket的buffer中; 最后将kernel模式下的socket buffer的数据copy到网卡设备中传送; 方式2:Calling mmap tmp_buf = mmap(file, len); write(socket, tmp_buf, len); 首先(通过DMA)将数据从磁盘读取到kernel buffer中; 然后将kernel buffer拷贝到socket buffer中; 最后将socket buffer中的数据copy到网卡设备(protocol engine)中发送; 其中mmap可以得到kernal buffer的引用,并直接进行使用 方式3:Replacing Read and Write with Sendfile sendfile(socket, file, len); 首先(通过DMA)将数据从磁盘读取到kernel buffer中;

UNP函数笔记十: 守护进程和inetd超级服务器

有些话、适合烂在心里 提交于 2019-11-27 23:30:57
第十三章 守护进程和inetd超级服务器: #include <syslog.h> void syslog(int priority, const char * format, ...); #include <syslog.h> void openlog(const char * ident, int option, int facility); void closelog(void); option: LOG_CONS, LOG_NDELAY, LOG_NOWAIT, LOG_ODELAY, LOG_PERROR, LOG_PID facility: LOG_AUTH, LOG_AUTHPRIV, LOG_CRON, LOG_DAEMON, LOG_FTP, LOG_KERN, LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7, LOG_LPR, LOG_MAIL, LOG_NEWS, LOG_SYSLOG, LOG_USER, LOG_UUCP level: LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG

同一端口监听tcp和udp请求

放肆的年华 提交于 2019-11-27 19:06:05
问题: 众所周知,同一台机器的同一个端口只可以被一个进程使用,一般用于tcp,或者udp。那一个进程使用同一个端口同时监听tcp、udp请求,是否可以呢?答案:可以。 代码: server 为了同时监听,server使用select进行多路访问控制。 server端代码如下: /* TCP INET use select */ #include<stdio.h> #include<stdlib.h> #include<string.h> #include<errno.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #define LENGTH_OF_LISTEN_QUEUE 20 #define SERVER_PORT 8888 #define MAXLINE 4096 #define MAX_FD_NUM 10 static int init_new_client( int client_fd); static int remove_client( int client_fd); static int get_max_fd( int fd); static int client_fdset[MAX_FD_NUM]; int main( int argc, char ** argv) {

python使用open的OSError: [Errno 22] Invalid argument错误

馋奶兔 提交于 2019-11-27 14:58:59
这两天在写一个新闻类的spider时,遇到了OSError: [Errno 22] Invalid argument这个错误,苦恼的两天,无果。后来通过请教学长,发现原来是打开的文件名中含有一些系统的敏感字符,结果就报错了。看一段简单的代码: 1 title = '把我看成新闻的*标题吧。' 2 contetn = '就把我看成是新闻的内容吧!!!' 3 with open(title+'.txt', 'a', encoding='utf-8') as f: 4 f.write(contetn) 5 6 # 报错内容如下: 7 # Traceback (most recent call last): 8 # File "E:/py project/my_spider/east_money/test2.py", line 3, in <module> 9 # with open(title+'.txt', 'a', encoding='utf-8') as f: 10 # OSError: [Errno 22] Invalid argument: '把我看成新闻的*标题吧。.txt' 可以看出,报错的内容在第三行,错误提示是无效的参数,观察一下第三行的代码,猜想应该是title里面的内容存在错误,试着把里面的那个 ‘*’ 去掉,结果报错没有了。原来

What does this socket.gaierror mean?

半城伤御伤魂 提交于 2019-11-27 14:34:13
I'm new to python and going through a book, Core Python Applications 3rd Edition. This is the the first example and already I'm stumped with it. Here's the code with the error at the end. #!/usr/bin/env python from socket import * from time import ctime HOST = ' ' PORT = 21567 BUFSIZ = 1024 ADDR = (HOST, PORT) tcpSerSock = socket(AF_INET, SOCK_STREAM) tcpSerSock.bind(ADDR) tcpSerSock.listen(5) while True: print 'waiting for connection...' tcpCliSock, addr = tcpSerSock.accept() print "...connected from:", addr while True: data = tcpCliSock.recv(BUFSIZ) if not data: break tcpCliSock.send("[%s]