accept() 함수

Network : 2007. 4. 27. 10:24
반응형

accep()는 최초 접근시입니다.

데이터의 일부로 봐도 좋겠으나 접근시도라고 보는편이 맞겠네요.


그후의 데이터 전송 수신은 read, write 윈도우는 recv, send 라고는 함수를 사용하지요.

accept 함수 호출 == 사용자 접근 횟수 입니다.

1번 접근하면 그 이후의 데이터 수신 송신은 프로그래머 마음입니다.


accep == connect죠 서버 <=> 클라이언트 관계에선..

저 둘의 관계가 적용되는겁니다.


msdn

accept

The accept function permits an incoming connection attempt on a socket.

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

Parameters

s
[in] Descriptor that identifies a socket that has been placed in a listening state with the listen function. The connection is actually made with the socket that is returned by accept.
addr
[out] Optional pointer to a buffer that receives the address of the connecting entity, as known to the communications layer. The exact format of the addr parameter is determined by the address family that was established when the socket from the sockaddr structure was created.
addrlen
[in, out] Optional pointer to an integer that contains the length of addr.
/*accept 함수 - 듣기 소켓에 연결시도를 받아 들임
  첫번째 인자 - listen 함수를 통해서 듣기 상태에 들어간 소켓을 가리키는 소켓 식별자 실제 연결은
   accept 함수가 반환한 소켓과 이루어진다.
  두번째 인자 - 연결을 시도한 원격 소켓에 대한 정보를 돌려받을 버퍼를 가리키는 포인터
  세번째 인자 - 두번째인자의 길이~

 */

Return Values

If no error occurs, accept returns a value of type SOCKET that is a descriptor for the new socket. This returned value is a handle for the socket on which the actual connection is made.

Otherwise, a value of INVALID_SOCKET is returned, and a specific error code can be retrieved by calling WSAGetLastError.

The integer referred to by addrlen initially contains the amount of space pointed to by addr. On return it will contain the actual length in bytes of the address returned.

Error code Meaning
WSANOTINITIALISED A successful WSAStartup call must occur before using this function.
WSAECONNRESET An incoming connection was indicated, but was subsequently terminated by the remote peer prior to accepting the call.
WSAEFAULT The addrlen parameter is too small or addr is not a valid part of the user address space.
WSAEINTR A blocking Windows Sockets 1.1 call was canceled through WSACancelBlockingCall.
WSAEINVAL The listen function was not invoked prior to accept.
WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
WSAEMFILE The queue is nonempty upon entry to accept and there are no descriptors available.
WSAENETDOWN The network subsystem has failed.
WSAENOBUFS No buffer space is available.
WSAENOTSOCK The descriptor is not a socket.
WSAEOPNOTSUPP The referenced socket is not a type that supports connection-oriented service.
WSAEWOULDBLOCK The socket is marked as nonblocking and no connections are present to be accepted.

Remarks

The accept function extracts the first connection on the queue of pending connections on socket s. It then creates and returns a handle to the new socket. The newly created socket is the socket that will handle the actual connection; it has the same properties as socket s, including the asynchronous events registered with the WSAAsyncSelect or WSAEventSelect functions.

The accept function can block the caller until a connection is present if no pending connections are present on the queue, and the socket is marked as blocking. If the socket is marked as nonblocking and no pending connections are present on the queue, accept returns an error as described in the following. After the successful completion of accept returns a new socket handle, the accepted socket cannot be used to accept more connections. The original socket remains open and listens for new connection requests.

The parameter addr is a result parameter that is filled in with the address of the connecting entity, as known to the communications layer. The exact format of the addr parameter is determined by the address family in which the communication is occurring. The addrlen is a value-result parameter; it should initially contain the amount of space pointed to by addr; on return it will contain the actual length (in bytes) of the address returned.

The accept function is used with connection-oriented socket types such as SOCK_STREAM. If addr and/or addrlen are equal to NULL, then no information about the remote address of the accepted socket is returned.

반응형
Posted by Real_G