IOCP °ü·Ã ÇÔ¼ö
 FrontPage|FindPage|TitleIndex|RecentChanges|UserPreferences E D R S P I M H RSS

FortuneCookiesFreeBSD »ç¿ëÇϱâGame AI ProgrammingGame Development CompanyGame Development Links › IOCP°ü·ÃÇÔ¼ö
Contents:
1 °ü·Ã¼­Àû
2 CreateIoCompletionPort() ÇÔ¼ö
2.1 ¹Ýȯ°ª


1 °ü·Ã¼­Àû #


  • NETWORK PROGRAMMING FOR MICROSOFT WINDOWS
    • Anthony Jones.Jim Ohlund °øÀú, ±è³²½Ä ¿ª, Á¤º¸¹®È­»ç

2 CreateIoCompletionPort() ÇÔ¼ö #


HANDLE CreateIoCompletionPort(
	HANDLE    FileHandle,
	HANDLE    ExistingCompletionPort,
	ULONG_PTR CompletionKey,
	DWORD     NumberOfConcurrentThreads
);

2.1 Àμö #


  • FileHandle
    [in] Handle to a file opened for overlapped I/O completion. You must specify the FILE_FLAG_OVERLAPPED flag when using the CreateFile function to obtain the handle.

    If FileHandle specifies INVALID_HANDLE_VALUE, CreateIoCompletionPort creates an I/O completion port without associating it with a file. In this case, the ExistingCompletionPort parameter must be NULL and the CompletionKey parameter is ignored.

  • ExistingCompletionPort
    [in] Handle to the I/O completion port.

    If this parameter specifies an existing completion port, the function associates it with the file specified by the FileHandle parameter. The function returns the handle of the existing completion port; it does not create a new I/O completion port.

    If this parameter is NULL, the function creates a new I/O completion port and associates it with the file specified by FileHandle. The function returns the handle to the new I/O completion port.

  • CompletionKey
    [in] Per-file completion key that is included in every I/O completion packet for the specified file.

  • NumberOfConcurrentThreads
    [in] Maximum number of threads that the operating system can allow to concurrently process I/O completion packets for the I/O completion port. If this parameter is zero, the system allows as many concurrently running threads as there are processors in the system.

    Although any number of threads can call the GetQueuedCompletionStatus function to wait for an I/O completion port, each thread is associated with only one completion port at a time. That port is the port that was last checked by the thread.

    When a packet is queued to a port, the system first checks how many threads associated with the port are running. If the number of threads running is less than the value of NumberOfConcurrentThreads, then one of the waiting threads is allowed to process the packet. When a running thread completes its processing, it calls GetQueuedCompletionStatus again, at which point the system can allow another waiting thread to process a packet.

    The system also allows a waiting thread to process a packet if a running thread enters any wait state. When the thread in the wait state begins running again, there may be a brief period when the number of active threads exceeds the NumberOfConcurrentThreads value. However, the system quickly reduces the number by not allowing any new active threads until the number of active threads falls below the specified value.

2.2 ¹Ýȯ°ª #



3 GetQueuedCompletionStatus() ÇÔ¼ö #


BOOL GetQueuedCompletionStatus(
	HANDLE         CompletionPort,
	LPDWORD        lpNumberOfBytes,
	PULONG_PTR     lpCompletionKey,
	LPOVERLAPPED * lpOverlapped,
	DWORD          dwMilliseconds
);

3.1 Àμö #


  • CompletionPort
    [in] Handle to the completion port of interest. To create a completion port, use the CreateIoCompletionPort function.

  • lpNumberOfBytes
    [out] Pointer to a variable that receives the number of bytes transferred during an I/O operation that has completed.

  • lpCompletionKey
    [out] Pointer to a variable that receives the completion key value associated wit h the file handle whose I/O operation has completed. A completion key is a per-file key that is specified in a call to CreateIoCompletionPort.

  • lpOverlapped
    [out] Pointer to a variable that receives the address of the OVERLAPPED structure that was specified when the completed I/O operation was started.

    The following functions can be used to start I/O operations that complete using completion ports. You must pass the function an OVERLAPPED structure and a file handle associated with an comp letion port (by a call to CreateIoCompletionPort) to invoke the I/O completion port mechanism:

    • ConnectNamedPipe
    • DeviceIoControl
    • LockFileEx
    • ReadDirectoryChangesW
    • ReadFile
    • TransactNamedPipe
    • WaitCommEvent
    • WriteFile

  • Even if you have passed the function a file handle associated with a completion port and a valid OVERLAPPED structure, an application can prevent completion port notification. This is done by specifying a valid event handle for the hEvent member of the OVERLAPPED structure, and setting its low-order bit. A valid event handle whose low-order bit is set keeps I/O completion from being queued to the completion port.

  • dwMilliseconds
    [in] Number of milliseconds that the caller is willing to wait for an completion packet to appear at the completion port. If a completion packet doesn't appear within the specified time, the function times out, returns FALSE, and sets *lpOverlapped to NULL.

    If dwMilliseconds is INFINITE, the function will never time out. If dwMilliseconds is zero and there is no I/O operation to dequeue, the function will time out immediately.


3.2 ¹Ýȯ°ª #


Completion port ·ÎºÎÅÍ I/O µ¿ÀÛ ¿Ï·á ÅëÁö¸¦ ¹Þ¾ÒÀ» °æ¿ì, 0 ÀÌ ¾Æ´Ñ °ªÀ» ¹ÝȯÇÑ´Ù. À̶§ ÇÔ¼ö´Â lpNumberOfBytesTransferred ¿Í lpCompletionKey, lpOverlapped Àμö¿¡ ÀÌ¿Í °ü·ÃµÈ Á¤º¸µéÀ» ¹ÝȯÇÑ´Ù.

*lpOverlapped °ªÀÌ NULL À̰í Completion port ·ÎºÎÅÍ µ¿ÀÛ ¿Ï·á ÅëÁö¸¦ ¸ø¹Þ¾ÒÀ» °æ¿ì, 0 À» ¹ÝȯÇÑ´Ù. À̶§ ÇÔ¼ö´Â lpNumberOfBytes ¿Í lpCompletionKey Àμö¿¡ ÀÌ¿Í °ü·ÃµÈ Á¤º¸¸¦ ÀúÀåÇÏÁö ¾Ê´Â´Ù. ¿¡·¯ Á¤º¸¸¦ ¾ò±â À§Çؼ­´Â GetLastError() ÇÔ¼ö¸¦ È£ÃâÇÑ´Ù. ¸¸¾à ŸÀÓ-¾Æ¿ô¿¡ ÀÇÇÏ¿© ¿Ï·áÅëÁö¸¦ ¸ø¹Þ¾ÒÀ» °æ¿ì GetLastError() ÇÔ¼ö´Â WAIT_TIMEOUT ¸¦ ¹ÝȯÇÑ´Ù.

*lpOverlapped °ªÀÌ NULL ÀÌ ¾Æ´Ï°í Completion port ·ÎºÎÅÍ µ¿ÀÛ ¿Ï·á ½ÇÆÐ ÅëÁö¸¦ ¹Þ¾ÒÀ» °æ¿ì, 0 À» ¹ÝȯÇÑ´Ù. À̶§ ÇÔ¼ö´Â lpNumberOfBytes ¿Í lpCompletionKey, lpOverlapped Àμö¿¡ ÀÌ¿Í °ü·ÃµÈ Á¤º¸¸¦ ÀúÀåÇÑ´Ù. ¿¡·¯ Á¤º¸¸¦ ¾ò±â À§Çؼ­´Â GetLastError() ÇÔ¼ö¸¦ È£ÃâÇÑ´Ù.

Completion port ¿Í ¿¬°üµÈ ¼ÒÄÏ ÇÚµéÀ» ´Ý°åÀ» °æ¿ì, GetQueuedCompletionStatus() ÇÔ¼ö´Â ERROR_SUCCESS ¸¦ ¹ÝȯÇϸç lpNumberOfBytes Àμö´Â 0 ÀÌ µÈ´Ù.

°á°ú¹Ýȯ°ªlpNumberOfByteslpCompletionKeylpOverlapped
I/O µ¿ÀÛ ¿Ï·á Non-Zero * * *
I/O µ¿ÀÛ ½ÇÆÐ 0 * * *
Time-Out 0 x x NULL
¼ÒÄÏ ´ÝÈû ERROR_SUCCESS 0 * *
Âü°í> 0:Zero, *:°ª ÀúÀå, x:°ª ÀúÀå ¾ÈÇÔ


4 PostQueuedCompletionStatus() ÇÔ¼ö #


BOOL PostQueuedCompletionStatus(
	HANDLE       CompletionPort,
	DWORD        dwNumberOfBytesTransferred,
	ULONG_PTR    dwCompletionKey,
	LPOVERLAPPED lpOverlapped
);

4.1 Àμö #


  • CompletionPort
    [in] Handle to an I/O completion port to which the I/O completion packet is to be posted.

  • dwNumberOfBytesTransferred
    [in] Value to be returned through the lpNumberOfBytesTransferred parameter of the GetQueuedCompletionStatus function.

  • dwCompletionKey
    [in] Value to be returned through the lpCompletionKey parameter of the GetQueuedCompletionStatus function.

  • lpOverlapped
    [in] Value to be returned through the lpOverlapped parameter of the GetQueuedCompletionStatus function.

4.2 ¹Ýȯ°ª #




SubCategoryNetwork

EditText|FindPage|DeletePage|LikePages| Valid XHTML 1.0! Valid CSS! powered by MoniWiki