當前位置:首頁 » 操作系統 » linuxerrno

linuxerrno

發布時間: 2022-08-18 08:04:57

1. linux 非阻塞connect errno什麼情況下不為einprogress

當connect在非阻塞模式下,會出現返回-1值,錯誤碼是EINPROGRESS,但如何判斷connect是聯通的呢?stevens書中說明要在connect後,繼續判斷該socket是否可寫?

若可寫,則證明鏈接成功。如何判斷可寫,有2種方案,一種是select判斷是否可寫,二用poll模型。

select:
int CheckConnect(int iSocket)
{
fd_set rset;

FD_ZERO(&rset);
FD_SET(iSocket, &rset);

timeval tm;
tm. tv_sec = 0;
tm.tv_usec = 0;

if ( select(iSocket + 1, NULL, &rset, NULL, &tval) <= 0)
{
close(iSocket);
return -1;
}

if (FD_ISSET(iSocket, &rset))
{
int err = -1;
socklen_t len = sizeof(int);
if ( getsockopt(iSocket, SOL_SOCKET, SO_ERROR ,&err, &len) < 0 )
{
close(iSocket);
printf("errno:%d %s\n", errno, strerror(errno));
return -2;
}

if (err)
{
errno = err;
close(iSocket);

return -3;
}
}

return 0;
}

poll:

int CheckConnect(int iSocket) {
struct pollfd fd;
int ret = 0;
socklen_t len = 0;

fd.fd = iSocket;
fd.events = POLLOUT;

while ( poll (&fd, 1, -1) == -1 ) {
if( errno != EINTR ){
perror("poll");
return -1;
}
}

len = sizeof(ret);
if ( getsockopt (iSocket, SOL_SOCKET, SO_ERROR, &ret, &len) == -1 ) {
perror("getsockopt");
return -1;
}

if(ret != 0) {
fprintf (stderr, "socket %d connect failed: %s\n",
iSocket, strerror (ret));
return -1;
}

return 0;
}

2. linux如何直接取得當前的errno值

你都知道是空指針了,你還想看什麼錯誤?你是想知道它什麼時候變空了嗎?可以打一些段點之類的。

3. linux是如何設置errno的

誰設置的errno 肯定不是open函數吧 你想錯了,就是它設置的

在系統調用函數中,都會有這樣的代碼處理。這就是系統提供的函數的功能。

4. linux 取得socket 怎麼取得errorno

#include <errno.h>

extern int errno;

然後出現錯誤後errno會被重置,你直接列印就可以看到了

5. linux 下 errno=110是什麼意思

errno.110 is: Connection timed out

6. linux中編程中errno != EINTR

在linuxC的read函數中,errno = EINTR時表示因為中斷而暫停。那麼這個if的條件句意思是返回值為-1並且不是由於中斷而停止調用的意思。

7. linux 程序能修改errno的值嗎

默認情況下,只要返回值不是0,linux都會認為這次的結果是錯誤的
所以你可以定義你的error值為任何非0值

熱點內容
用中文編譯的編程軟體 發布:2025-09-16 09:04:37 瀏覽:137
語音編譯器教程 發布:2025-09-16 08:57:44 瀏覽:442
sql注冊伺服器 發布:2025-09-16 08:53:17 瀏覽:605
嵌入式linuxc編程入門 發布:2025-09-16 08:24:18 瀏覽:378
碼片編程器 發布:2025-09-16 08:24:08 瀏覽:947
原神各畫質要什麼配置 發布:2025-09-16 08:17:32 瀏覽:316
讀取資料庫生成xml 發布:2025-09-16 08:17:19 瀏覽:793
sql2000開發版 發布:2025-09-16 07:56:31 瀏覽:802
linux桌面哪個 發布:2025-09-16 07:55:35 瀏覽:55
python讀取網頁 發布:2025-09-16 07:45:05 瀏覽:338