成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

accept 中文man頁面

系統(tǒng)
accept 函數(shù)用于基于連接的套接字 (SOCK_STREAM, SOCK_SEQPACKET 和 SOCK_RDM). 它從未完成連接隊(duì)列中取出第一個(gè)連接請(qǐng)求,創(chuàng)建一個(gè)和參數(shù) s 屬性相同的連接套接字,并為這個(gè)套接字分配一個(gè)文件描述符, 然后以這個(gè)描述符返回.新創(chuàng)建的描述符不再處于傾聽狀態(tài).原套接字 s 不受此調(diào)用的影響.注意任意一個(gè)文件描述符標(biāo)志 (任何可以被 fcntl以參數(shù) F_SETFL 設(shè)置的值,比如非阻塞式或者異步狀態(tài))不會(huì)被 accept. 所繼承.

NAME 名稱

accept - 在一個(gè)套接字上接收一個(gè)連接  

SYNOPSIS 概述

#include <sys/types.h>
#include <sys/socket.h>

int accept(int s, struct sockaddr *addr, socklen_t *addrlen);  

DESCRIPTION 描述

accept 函數(shù)用于基于連接的套接字 (SOCK_STREAM, SOCK_SEQPACKETSOCK_RDM). 它從未完成連接隊(duì)列中取出第一個(gè)連接請(qǐng)求,創(chuàng)建一個(gè)和參數(shù) s 屬性相同的連接套接字,并為這個(gè)套接字分配一個(gè)文件描述符, 然后以這個(gè)描述符返回.新創(chuàng)建的描述符不再處于傾聽狀態(tài).原套接字 s 不受此調(diào)用的影響.注意任意一個(gè)文件描述符標(biāo)志 (任何可以被 fcntl以參數(shù) F_SETFL 設(shè)置的值,比如非阻塞式或者異步狀態(tài))不會(huì)被 accept. 所繼承.

參數(shù) s 是以 socket(2) 創(chuàng)建,用 bind(2) 綁定到一個(gè)本地地址,并且在調(diào)用了 listen(2). 之后正在偵聽一個(gè)連接的套接字. 參數(shù) addr 是一個(gè)指向結(jié)構(gòu)sockaddr的指針.這個(gè)結(jié)構(gòu)體以連接實(shí)體地址填充. 所謂的連接實(shí)體,就是眾所周知的網(wǎng)絡(luò)層.參數(shù) addr 所傳遞的真正的地址格式依賴于所使用的套接字族. (參見 socket(2) 和各協(xié)議自己的手冊(cè)頁). addrlen 是一個(gè)實(shí)時(shí)參數(shù): 它的大小應(yīng)該能夠足以容納參數(shù) addr 所指向的結(jié)構(gòu)體;在函數(shù)返回時(shí)此參數(shù)將以字節(jié)數(shù)表示出返回地址的實(shí)際長(zhǎng)度.若 addr 使用NULL作為參數(shù),addrlen將也被置為NULL.

如果隊(duì)列中沒有未完成連接套接字,并且套接字沒有標(biāo)記為非阻塞式, accept 將阻塞直到一個(gè)連接到達(dá).如果一個(gè)套接字被標(biāo)記為非阻塞式而隊(duì)列中沒有未完成連接套接字, accept 將返回EAGAIN.

使用 select(2) 或者 poll(2). 可以在一個(gè)套接字上有連接到來時(shí)產(chǎn)生事件.當(dāng)嘗試一個(gè)新的連接時(shí)套接字讀就緒,這樣我們就可以調(diào)用 accept 為這個(gè)連接獲得一個(gè)新的套接字.此外,你還可以設(shè)置套接字在喚醒時(shí)接收到信號(hào) SIGIO; 細(xì)節(jié)請(qǐng)參見 socket(7)

對(duì)于那些需要顯式確認(rèn)的協(xié)議,比如 DECNet, accept 可以看作僅僅從隊(duì)列中取出下一個(gè)連接而不做確認(rèn).當(dāng)在這個(gè)新的文件描述符上進(jìn)行普通讀寫操作時(shí)暗示了確認(rèn),當(dāng)關(guān)閉這個(gè)新的套接字時(shí)暗示了拒絕.目前在Linux上只有DECNet有這樣的含義.  

NOTES 注意

當(dāng)接收到一個(gè) SIGIO 信號(hào)或者 select(2) 或 poll(2) 返回讀就緒并不總是意味著有新連接在等待,因?yàn)檫B接可能在調(diào)用 accept 之前已經(jīng)被異步網(wǎng)絡(luò)錯(cuò)誤或者其他線程所移除.如果發(fā)生這種情況, 那么調(diào)用將阻塞并等待下一個(gè)連接的到來.為確保 accept 永遠(yuǎn)不會(huì)阻塞,傳遞的套接字 s 需要置 O_NONBLOCK 標(biāo)志(參見 socket(7)).  

RETURN VALUE 返回值

此調(diào)用在發(fā)生錯(cuò)誤時(shí)返回-1.若成功則返回一個(gè)非負(fù)整數(shù)標(biāo)識(shí)這個(gè)連接套接字.  

ERROR HANDLING 錯(cuò)誤處理

Linux accept 將一個(gè)待處理網(wǎng)絡(luò)錯(cuò)誤代碼通過 accept 傳遞給新套接字 . 這種處理方式有別于其他的BSD套接字實(shí)現(xiàn).為可靠操作,應(yīng)用程序必須在調(diào)用 accept 之后能夠檢測(cè)這些為協(xié)議定義的網(wǎng)絡(luò)錯(cuò)誤,并且以重試解決,就象 EAGAIN 一樣.對(duì)于TCP/IP這些網(wǎng)絡(luò)錯(cuò)誤是 ENETDOWN, EPROTO, ENOPROTOOPT, EHOSTDOWN, ENONET, EHOSTUNREACH, EOPNOTSUPP, 以及 ENETUNREACH.  

ERRORS 錯(cuò)誤

EAGAIN或者EWOULDBLOCK
套接字被標(biāo)記為非阻塞,且當(dāng)前沒有可接收的連接.
EBADF
描述符非法.
ENOTSOCK
描述符指向一個(gè)文件,而不是一個(gè)套接字.
EOPNOTSUPP
作為參數(shù)的套接字不是 SOCK_STREAM. 類型
EFAULT
參數(shù) addr 不在用戶可寫地址空間之內(nèi).
EPERM
防火墻規(guī)則禁止連接.
ENOBUFS,ENOMEM
沒有足夠內(nèi)存. 這個(gè)錯(cuò)誤一般來說意味著內(nèi)存分配受套接字緩沖區(qū)所限, 而不是沒有系統(tǒng)內(nèi)存.

另外,新套接字和協(xié)議中定義的網(wǎng)絡(luò)錯(cuò)誤也可能被返回. 不同的Linux內(nèi)核也可能返回下列錯(cuò)誤 EMFILE, EINVAL, ENOSR, ENOBUFS, EPERM, ECONNABORTED, ESOCKTNOSUPPORT, EPROTONOSUPPORT, ETIMEDOUT, ERESTARTSYS.  

CONFORMING TO 兼容于

SVr4,4.4BSD( accept 函數(shù)首次出現(xiàn)于BSD 4.2). BSD手冊(cè)頁文檔定義了五個(gè)可能的錯(cuò)誤返回值 (EBADF, ENOTSOCK, EOPNOTSUPP, EWOULDBLOCK, EFAULT). SUSv2文檔的定義是EAGAIN, EBADF, ECONNABORTED, EFAULT, EINTR, EINVAL, EMFILE, ENFILE, ENOBUFS, ENOMEM, ENOSR, ENOTSOCK, EOPNOTSUPP, EPROTO, EWOULDBLOCK.

Linux accept不繼承象 O_NONBLOCK 這樣的套接字標(biāo)志. 這一點(diǎn)有別于其他的BSD套接字實(shí)現(xiàn). 因此,程序應(yīng)該在accept所返回的套接字上設(shè)置所有需要的標(biāo)志.  

NOTE 注意

函數(shù) accept 的第三個(gè)參數(shù)原來被聲明為'int *'(在libc4和libc5以及其他很多系統(tǒng)中, 比如BSD 4.*,SunOS 4, SGI);POSIX 1003.1g草案試圖將其改變?yōu)?`size_t *',SunOS 5就是這么做的. 后來的POSIX草案和Single Unix Specification以及glibc2使用了 `socklen_t *'. Quoting Linus Torvalds: 引自Linus Torvalds (譯注:這個(gè)家伙就是Linux的創(chuàng)始人,所以我保留了他老人家的原文, 僅將原文大意附后): I fails: only italicizes a single line _Any_ sane library _must_ have "socklen_t" be the same size as int. Anything else breaks any BSD socket layer stuff. POSIX initially _did_ make it a size_t, and I (and hopefully others, but obviously not too many) complained to them very loudly indeed. Making it a size_t is completely broken, exactly because size_t very seldom is the same size as "int" on 64-bit architectures, for example. And it _has_ to be the same size as "int" because that's what the BSD socket interface is. Anyway, the POSIX people eventually got a clue, and created "socklen_t". They shouldn't have touched it in the first place, but once they did they felt it had to have a named type for some unfathomable reason (probably somebody didn't like losing face over having done the original stupid thing, so they silently just renamed their blunder).

數(shù)據(jù)類型"socklen_t"和int應(yīng)該具有相同的長(zhǎng)度.否則就會(huì)破壞 BSD套接字層的填充.POSIX開始的時(shí)候用的是size_t, Linus Torvalds(他希望有更多的人,但顯然不是很多) 努力向他們解釋使用size_t是完全錯(cuò)誤的,因?yàn)樵?4位結(jié)構(gòu)中 size_t和int的長(zhǎng)度是不一樣的,而這個(gè)參數(shù)(也就是accept函數(shù)的第三參數(shù))的長(zhǎng)度必須和int一致,因?yàn)檫@是BSD套接字接口標(biāo)準(zhǔn).最終POSIX的那幫家伙找到了解決的辦法,那就是創(chuàng)造了一個(gè)新的類型"socklen_t".Linux Torvalds說這是由于他們發(fā)現(xiàn)了自己的錯(cuò)誤但又不好意思向大家伙兒承認(rèn),所以另外創(chuàng)造了一個(gè)新的數(shù)據(jù)類型.  

SEE ALSO 參見

bind(2), connect(2), listen(2), select(2), socket(2)

#p#

NAME

accept - accept a connection on a socket  

SYNOPSIS

#include <sys/types.h>
#include <sys/socket.h>

int accept(int s, struct sockaddr *addr, socklen_t *addrlen);  

DESCRIPTION

The accept function is used with connection-based socket types (SOCK_STREAM, SOCK_SEQPACKET and SOCK_RDM). It extracts the first connection request on the queue of pending connections, creates a new connected socket with mostly the same properties as s, and allocates a new file descriptor for the socket, which is returned. The newly created socket is no longer in the listening state. The original socket s is unaffected by this call. Note that any per file descriptor flags (everything that can be set with the F_SETFL fcntl, like non blocking or async state) are not inherited across an accept.

The argument s is a socket that has been created with socket(2), bound to a local address with bind(2), and is listening for connections after a listen(2).

The argument addr is a pointer to a sockaddr structure. This structure is filled in with the address of the connecting entity, as known to the communications layer. The exact format of the address passed in the addr parameter is determined by the socket's family (see socket(2) and the respective protocol man pages). The addrlen argument is a value-result parameter: it should initially contain the size of the structure pointed to by addr; on return it will contain the actual length (in bytes) of the address returned. When addr is NULL nothing is filled in.

If no pending connections are present on the queue, and the socket is not marked as non-blocking, accept blocks the caller until a connection is present. If the socket is marked non-blocking and no pending connections are present on the queue, accept returns EAGAIN.

In order to be notified of incoming connections on a socket, you can use select(2) or poll(2). A readable event will be delivered when a new connection is attempted and you may then call accept to get a socket for that connection. Alternatively, you can set the socket to deliver SIGIO when activity occurs on a socket; see socket(7) for details.

For certain protocols which require an explicit confirmation, such as DECNet, accept can be thought of as merely dequeuing the next connection request and not implying confirmation. Confirmation can be implied by a normal read or write on the new file descriptor, and rejection can be implied by closing the new socket. Currently only DECNet has these semantics on Linux.  

NOTES

There may not always be a connection waiting after a SIGIO is delivered or select(2) or poll(2) return a readability event because the connection might have been removed by an asynchronous network error or another thread before accept is called. If this happens then the call will block waiting for the next connection to arrive. To ensure that accept never blocks, the passed socket s needs to have the O_NONBLOCK flag set (see socket(7)).  

RETURN VALUE

The call returns -1 on error. If it succeeds, it returns a non-negative integer that is a descriptor for the accepted socket.  

ERROR HANDLING

Linux accept passes already-pending network errors on the new socket as an error code from accept. This behaviour differs from other BSD socket implementations. For reliable operation the application should detect the network errors defined for the protocol after accept and treat them like EAGAIN by retrying. In case of TCP/IP these are ENETDOWN, EPROTO, ENOPROTOOPT, EHOSTDOWN, ENONET, EHOSTUNREACH, EOPNOTSUPP, and ENETUNREACH.  

ERRORS

accept shall fail if:

EAGAIN or EWOULDBLOCK
The socket is marked non-blocking and no connections are present to be accepted.
EBADF
The descriptor is invalid.
ENOTSOCK
The descriptor references a file, not a socket.
EOPNOTSUPP
The referenced socket is not of type SOCK_STREAM.
EINTR
The system call was interrupted by a signal that was caught before a valid connection arrived.
ECONNABORTED
A connection has been aborted.
EINVAL
Socket is not listening for connections.
EMFILE
The per-process limit of open file descriptors has been reached.
ENFILE
The system maximum for file descriptors has been reached.

accept may fail if:

EFAULT
The addr parameter is not in a writable part of the user address space.
ENOBUFS, ENOMEM
Not enough free memory. This often means that the memory allocation is limited by the socket buffer limits, not by the system memory.
EPROTO
Protocol error.

Linux accept may fail if:

EPERM
Firewall rules forbid connection.

In addition, network errors for the new socket and as defined for the protocol may be returned. Various Linux kernels can return other errors such as ENOSR, ESOCKTNOSUPPORT, EPROTONOSUPPORT, ETIMEDOUT. The value ERESTARTSYS may be seen during a trace.  

CONFORMING TO

SVr4, 4.4BSD (the accept function first appeared in BSD 4.2). The BSD man page documents five possible error returns (EBADF, ENOTSOCK, EOPNOTSUPP, EWOULDBLOCK, EFAULT). SUSv3 documents errors EAGAIN, EBADF, ECONNABORTED, EINTR, EINVAL, EMFILE, ENFILE, ENOBUFS, ENOMEM, ENOTSOCK, EOPNOTSUPP, EPROTO, EWOULDBLOCK. In addition, SUSv2 documents EFAULT and ENOSR.

Linux accept does _not_ inherit socket flags like O_NONBLOCK. This behaviour differs from other BSD socket implementations. Portable programs should not rely on this behaviour and always set all required flags on the socket returned from accept.  

NOTE

The third argument of accept was originally declared as an `int *' (and is that under libc4 and libc5 and on many other systems like BSD 4.*, SunOS 4, SGI); a POSIX 1003.1g draft standard wanted to change it into a `size_t *', and that is what it is for SunOS 5. Later POSIX drafts have `socklen_t *', and so do the Single Unix Specification and glibc2. Quoting Linus Torvalds: _Any_ sane library _must_ have "socklen_t" be the same size as int. Anything else breaks any BSD socket layer stuff. POSIX initially _did_ make it a size_t, and I (and hopefully others, but obviously not too many) complained to them very loudly indeed. Making it a size_t is completely broken, exactly because size_t very seldom is the same size as "int" on 64-bit architectures, for example. And it _has_ to be the same size as "int" because that's what the BSD socket interface is. Anyway, the POSIX people eventually got a clue, and created "socklen_t". They shouldn't have touched it in the first place, but once they did they felt it had to have a named type for some unfathomable reason (probably somebody didn't like losing face over having done the original stupid thing, so they silently just renamed their blunder).  

SEE ALSO

bind(2), connect(2), listen(2), select(2), socket(2)

責(zé)任編輯:韓亞珊 來源: CMPP.net
相關(guān)推薦

2011-08-24 16:48:36

man中文man

2011-08-15 10:21:09

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-08-11 15:03:21

ACCESS中文man

2011-08-11 15:28:43

ali中文man

2011-08-11 16:31:49

biff中文man

2011-08-11 16:48:04

cal中文man

2011-08-11 17:16:43

cce中文man

2011-08-11 18:05:04

chvt中文man

2011-08-11 18:13:07

clear中文man

2011-08-12 09:13:02

df中文man

2011-08-12 09:38:06

dircolors中文man

2011-08-12 09:44:37

dirname中文man

2011-08-12 10:20:02

echo中文man

2011-08-12 10:25:55

eject中文man

2011-08-12 11:07:19

git中文man

2011-08-12 13:18:19

head中文man

2011-08-12 13:49:23

hostid中文man

2011-08-12 13:54:46

hostname中文man
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 精品中文视频 | 天天操夜夜操 | 中文字幕一区二区在线观看 | 日韩一区二区免费视频 | 国产羞羞视频在线观看 | 国产精品一区二区三区在线 | 国产aa| 国产黄色小视频在线观看 | 99精品久久久久 | 在线免费观看视频你懂的 | 一级片免费网站 | 91一区| 欧美亚洲在线视频 | 亚洲欧洲色视频 | 久久国产亚洲 | 欧美亚洲日本 | 日韩伦理电影免费在线观看 | www.久久久久久久久久久 | 一区二区中文字幕 | 日韩影音 | 精品三区 | 四虎国产 | 日韩中文字幕网 | 久久涩涩 | 国产激情在线 | 欧洲免费视频 | 夜久久| 99pao成人国产永久免费视频 | 在线日韩欧美 | 久久一区二区av | 国产大片一区 | 国产精品久久久久久模特 | 91久久精品一区二区二区 | h视频免费在线观看 | 亚洲天堂成人在线视频 | 久久久久国产一区二区三区四区 | 久久久久网站 | 华丽的挑战在线观看 | 久久夜视频 | 97精品超碰一区二区三区 | 男插女下体视频 |