errno

Socket bind failed errno = 99

一曲冷凌霜 提交于 2019-12-22 07:39:07
问题 I'm trying to bind the server socket so I can receive and listen for incoming messages from other clients. But I can't bind, it returns an error - Socket bind failed: 99. I read up what does it mean and it says that errno 99 indicates that the socket does not exist? Any ideas? Thanks UDP_socketID = socket(AF_INET, SOCK_DGRAM, 0); if (UDP_socketID < 0) { printf("Socket creation failed! Error = %d\n\n", errno); exit(0); } //specify server address, port and IP bzero((char *)&serverAddr, sizeof

In Windows, is there any way to convert an errno into an HRESULT?

筅森魡賤 提交于 2019-12-22 05:28:12
问题 I know the HRESULT_FROM_WIN32 macro to convert a Win32 error code into an HRESULT, is there any way to do the conversion starting from an errno error? 回答1: In short, no. As of http://msdn.microsoft.com/en-us/library/5814770t%28v=vs.100%29.aspx The errno values are constants assigned to errno in the event of various error conditions. ERRNO.H contains the definitions of the errno values. However, not all the definitions given in ERRNO.H are used in 32-bit Windows operating systems. Some of the

Unit testing error conditions - EINTR

丶灬走出姿态 提交于 2019-12-22 04:45:09
问题 In short, how do you unit test an error condition such as EINTR on a system call. One particular example I'm working on, which could be a case all by itself, is whether it's necessary to call fclose again when it returns EOF with (errno==EINTR). The behavior depends on the implementation of fclose: // Given an open FILE *fp while (fclose(fp)==EOF && errno==EINTR) { errno = 0; } This call can be unsafe if fp freed when EINTR occurs. How can I test the error handling for when (errno==EINTR)?

Symbolic errno to String

…衆ロ難τιáo~ 提交于 2019-12-21 08:18:17
问题 Is there a command-line tool that will take a symbolic errno such as EINVAL and print the corresponding string, Invalid argument ? I would like to avoid having to find that EINVAL is value 22 on my system and then using $ perror 22 . Ideally I could write something like $ errorcommand EINVAL Invalid argument $ 回答1: AFAIK, there isn't a standard tool that does the job. At one level, it wouldn't be particularly hard to write one - the messiest parts are finding the correct file to parse (is is

How to get the errno of an IOError?

喜你入骨 提交于 2019-12-20 09:46:14
问题 C has perror and errno, which print and store the last error encountered. This is convenient when doing file io as I do not have to fstat() every file that fails as an argument to fopen() to present the user with a reason why the call failed. I was wondering what is the proper way to grab errno when gracefully handling the IOError exception in python? In [1]: fp = open("/notthere") --------------------------------------------------------------------------- IOError Traceback (most recent call

PHP set_error_handler()函数的使用

此生再无相见时 提交于 2019-12-20 08:55:20
我们写程序,难免会有问题(是经常会遇到问题 ),而PHP遇到错误时,就会给出出错脚本的位置、行数和原因。有很多人说,这并没有什么大不了。确实,在调试程序阶段,这确实是没啥的,而且我认为给出错误路径是必要的。 但泄露了实际路径的后果是不堪设想的,对于某些入侵者,这个信息可是非常重要,而事实上现在有很多的服务器都存在这个问题。有些网管干脆把PHP配置文件中的display_errors设置为Off来解决(貌似我们就是这样做的),但本人认为这个方法过于消极。 有些时候,我们的确需要PHP返回错误的信息以便调试。而且在出错时也可能需要给用户一个交待,甚至导航到另一页面。 那么,有啥解决办法呢? set_error_handler() PHP从4.1.0开始提供了自定义错误处理句柄的功能函数set_error_handler(),但很少数脚本编写者知道。set_error_handler这个函数可以很好地防止错误路径泄露,当然还有其它更多的作用。 可以用来屏蔽错误。 出现错误一来会把一些信息暴漏给用户,极有可能成为黑客攻击你网站的工具。 二来让用户觉得你的水平很挫。 可以记下错误的信息, 及时发现一些生产环境的出现的问题。 可以做相应的处理, 出错的时候可以显示跳转到预先定义好的出错页面,提供更好的用户体验。 可以作为调试工具, 一些时候必须在生产环境调试一些东西,

微信公共号入口

冷暖自知 提交于 2019-12-19 06:06:09
<?php //引入微信类 include "wechat.class.php" ; //连接 $options = array ( 'token' = > 'Volunteer3033' , 'encodingaeskey' = > 'GEf4X0HgkYWKECviTeI6l64QozwitZ7zeGx3YGYZbxo' , 'appid' = > 'wx230439e1c0e0f753' , 'appsecret' = > 'bb8170f8f7cdf2dcad3e982da5a7716e' ) ; $weObj = new Wechat ( $options ) ; $weObj - > valid ( true ) ; //连接mysql数据库 $link = mysqli_connect ( '127.0.0.1' , 'xxx' , 'xxx' ) ; if ( mysqli_connect_errno ( $link ) ) { echo mysqli_connect_error ( $link ) ; exit ; } mysqli_select_db ( $link , 'xincishan' ) ; mysqli_set_charset ( $link , 'utf8' ) ; function query ( $link , $sql ) { $result

Return Code on failure. Positive or negative?

我是研究僧i 提交于 2019-12-19 03:13:10
问题 a C-programm can fail to execute under special circumstances in Linux. Example: You allocate some space and the OS denies it. char *buffer = (char *) malloc(1024); if (buffer == NULL) return ENOMEM; This failure is marked by the return code which is delivered to the OS. A return code of 0 (EXIT_SUCCESS) is marked as a successful execution. A return code which is not 0, is marked as a failure. So my question is, what is the convention, when a program detects an error. Should it return a

socket之命名、监听、连接、关闭

只谈情不闲聊 提交于 2019-12-19 01:30:24
命名socket   创建socket时,指定了地址族,但是并未指定使用该地址族中的那个具体socket地址。将一个socket与socket地址绑定称为给socket命名。在服务器程序中,我们通常要命名socket,因为只有命名后客户端才能知道该如何连接它。客户端通常不需要命名socket,而是采用匿名方式,即使用操作系统自动分配的socket地址。   命名的socket的系统调用是bind,定义如下:   bind将my_addr所指的socket地址分配给未命名的sockfd文件描述符,addrlen参数指定该socket地址的长度。   bind成功时返回0,失败则返回-1并设置errno:(常见的两种errno) 监听socket   socket被命名之后,还不能马上接收客户连接,我们需要使用如下系统调用来创建一个监听队列以存放待处理的客户连接:   sockfd参数指定被监听的socket。backlog参数提示内核监听队列的最大长度。监听队列的长度如果超过backlog,服务器将不受理新的客户连接,客户端也将受到ECONNREFUSED错误信息。(在内核版本2.2之前的Linux中,backlog参数是指所有处于半连接状态和完全连接状态的socket的上限。在此之后,他只表示处于完全连接状态的socket上限,处于半连接状态的socket的上限则由/proc

Access to errno from Python?

允我心安 提交于 2019-12-18 11:45:13
问题 I am stuck with a fairly complex Python module that does not return useful error codes (it actually fails disturbingly silently). However, the underlying C library it calls sets errno. Normally errno comes in over OSError attributes, but since I don't have an exception, I can't get at it. Using ctypes, libc.errno doesn't work because errno is a macro in GNU libc. Python 2.6 has some affordances but Debian still uses Python 2.5. Inserting a C module into my pure Python program just to read