fds

select only checks fds till 255 not till FD_SETSIZE

匿名 (未验证) 提交于 2019-12-03 03:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: select on fds higher then 255 do not check if the fd is open. Here is my example code: #include <stdio.h> #include <errno.h> #include <unistd.h> #include <sys/select.h> int main() { fd_set set; for(int i = 5;i<FD_SETSIZE;i++) { printf("--> i is %d\n", i); FD_ZERO(&set); FD_SET(i, &set); close(i); int retval = select(FD_SETSIZE, &set, NULL, NULL, NULL); if(-1 == retval) { perror("select"); } } } This results in: --> i is 5 select: Bad file descriptor ... --> i is 255 select: Bad file descriptor --> i is 256 Then the application blocks. Why

ldapsearch, django-ldap-auth and “data 52e, v1db1”

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to get django-auth-ldap working, but I keep getting invalid credentials (49) errors, despite having correct credentials: additional info: 80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db1 Using python-ldap (2.4.13) and django-auth-ldap (1.1.4) on Ubuntu 12.04.3 against Windows Server 2008 R2. I followed the installation instructions here: http://pythonhosted.org/django-auth-ldap/install.html and here: http://www.djm.org.uk/using-django-auth-ldap-active-directory-ldaps The second link

Too many open files in python

匿名 (未验证) 提交于 2019-12-03 01:27:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I wrote kind of a test suite which is heavily file intensive. After some time (2h) I get an IOError: [Errno 24] Too many open files: '/tmp/tmpxsqYPm' . I double checked all file handles whether I close them again. But the error still exists. I tried to figure out the number of allowed file descriptors using resource.RLIMIT_NOFILE and the number of currently opened file desciptors: def get_open_fds(): fds = [] for fd in range(3,resource.RLIMIT_NOFILE): try: flags = fcntl.fcntl(fd, fcntl.F_GETFD) except IOError: continue fds.append(fd) return

18匿名管道

匿名 (未验证) 提交于 2019-12-03 00:32:02
管道概念 进程间通信工具, 把数据从一端输出到另一端 半双工通信 无名管道(直接称之为管道), 只能用于父子进程或者兄弟进程间通信。 命名管道 , 可以用于所有进程间通信 管道创建 <unistd.h> int pipe( int fds[2] ) 成功返回 0 , 失败返回 -1 fds[0] 用于读取, fds[1] 用于写入 思路: 管道(单向)创建流程 (父进程发送信息到子进程) 1: 创建管道 pipe() 获取管道 fds[0] (读取), fds[1] (写入) 2: 创建子进程 fork() 子进程继承 fds[0], fds[1] 3: 父进程关闭读取功能 close(fds[0]) 4: 子进程关闭写入功能 close(fds[1]) 5:父进程写信息到 fds[1] 6:子进程读信息从 fds[0] 单向管道 例子: 父进程发送消息到子进程 #include <stdio.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #include <ctype.h> void testSinglePipe() { int fds[2]; pid_t pid; char buf[128]={0}; //-1 crete pipe fail if(pipe(fds)) { perror("fail

IO复用一select, poll, epoll用法说明

…衆ロ難τιáo~ 提交于 2019-12-02 11:02:21
三种IO复用类型 Select系统调用 #include<sys/select.h> int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* execptfds,struct timeval* timeout); #nfds表示监听的文件描述符总数; #readfds,writefds,execptfds分别表示对应的fd_set类型的集合 可以如下定义:fd_set readfds,writefds,execptfds #timeout表示select函数的超时时间 Struct timeval { Long tv_sec; Long tv_usec; } 如果timeval成员变量均为0,则select立即返回;如果timeout设置为NULL,则select将一直阻塞,直到某个文件描述符就绪。 # FD_ZERO(fd_set *fdset);清楚fdset的所有位,如FD_ZERO(&readfds); #FD_SET(int fd,fd_set* fdset);设置fdset的位,也就是将某个文件描述符加入到fdset中,如FD_SET(0,&readfds),将标准输入加入到fdset中 #int FD_ISSET(int fd,fd_set * fdset);测试fdset的某个位是否被设置

execjs使用时异常

让人想犯罪 __ 提交于 2019-12-01 20:15:59
一.异常信息 UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xa1 in position 26: illegal multibyte sequence 二.解决办法 进入报错源码 \lib\subprocess.py 因为是 codec 相关报错 就搜索 encoding ,为什么搜这个就是代码写多了 感觉 我们会发现这样一段 def __init__(self, args, bufsize=-1, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=True, shell=False, cwd=None, env=None, universal_newlines=None, startupinfo=None, creationflags=0, restore_signals=True, start_new_session=False, pass_fds=(), *, encoding=None, errors=None, text=None): #encoding是空怪不得是gbk报错 #直接修改encoding=utf8 解决啦~~ 来源: https://www.cnblogs.com/pythonywy/p

libusb阻塞

ε祈祈猫儿з 提交于 2019-11-28 22:05:48
这两天发现手头一个usb指纹头出现了一点状况,若libusb以同步方式发送bulk transfer出现阻塞。经过测试发现跟timeout有些关系:若timeout为0(无timeout),不会阻塞;若timeout为1000或者2000,则会。另外,若采用异步方式传送bulk transfer,则不会阻塞。 同步方式 libusb_bulk_transfer(devh, ep_bulk, buf, CAM_BUF_SZ, &len, timeout); 进入libusb研究,发现libusb是采用异步方式来实现的。在do_sync_bulk_transfer中: static int do_sync_bulk_transfer ( struct libusb_device_handle * dev_handle , unsigned char endpoint , unsigned char * buffer , int length , int * transferred , unsigned int timeout , unsigned char type ) { libusb_fill_bulk_transfer ( transfer , dev_handle , endpoint , buffer , length , bulk_transfer_cb , &