Click here to Skip to main content
15,913,310 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: firmware coding in C Pin
CPallini31-Jan-12 2:25
mveCPallini31-Jan-12 2:25 
AnswerRe: firmware coding in C Pin
Bram van Kampen31-Jan-12 12:27
Bram van Kampen31-Jan-12 12:27 
AnswerRe: firmware coding in C Pin
Erudite_Eric31-Jan-12 21:05
Erudite_Eric31-Jan-12 21:05 
Question::ifstream.open behaves differently in VC6 and VS2010 Pin
KASR130-Jan-12 22:31
KASR130-Jan-12 22:31 
AnswerRe: ::ifstream.open behaves differently in VC6 and VS2010 Pin
CPallini30-Jan-12 22:42
mveCPallini30-Jan-12 22:42 
GeneralRe: ::ifstream.open behaves differently in VC6 and VS2010 Pin
KASR131-Jan-12 3:24
KASR131-Jan-12 3:24 
AnswerRe: ::ifstream.open behaves differently in VC6 and VS2010 Pin
Albert Holguin31-Jan-12 3:37
professionalAlbert Holguin31-Jan-12 3:37 
GeneralRe: ::ifstream.open behaves differently in VC6 and VS2010 Pin
KASR131-Jan-12 3:42
KASR131-Jan-12 3:42 
AnswerRe: ::ifstream.open behaves differently in VC6 and VS2010 Pin
Albert Holguin31-Jan-12 5:17
professionalAlbert Holguin31-Jan-12 5:17 
GeneralRe: ::ifstream.open behaves differently in VC6 and VS2010 Pin
KASR11-Feb-12 7:29
KASR11-Feb-12 7:29 
Questionbasic Winsock / IOCP / UDP question Pin
SledgeHammer0130-Jan-12 13:01
SledgeHammer0130-Jan-12 13:01 
AnswerRe: basic Winsock / IOCP / UDP question Pin
Jochen Arndt30-Jan-12 22:19
professionalJochen Arndt30-Jan-12 22:19 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer0131-Jan-12 5:01
SledgeHammer0131-Jan-12 5:01 
GeneralRe: basic Winsock / IOCP / UDP question Pin
Jochen Arndt31-Jan-12 5:51
professionalJochen Arndt31-Jan-12 5:51 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer0131-Jan-12 6:27
SledgeHammer0131-Jan-12 6:27 
GeneralRe: basic Winsock / IOCP / UDP question Pin
Jochen Arndt31-Jan-12 6:43
professionalJochen Arndt31-Jan-12 6:43 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer0131-Jan-12 6:58
SledgeHammer0131-Jan-12 6:58 
GeneralRe: basic Winsock / IOCP / UDP question Pin
Jochen Arndt31-Jan-12 7:14
professionalJochen Arndt31-Jan-12 7:14 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer0131-Jan-12 7:19
SledgeHammer0131-Jan-12 7:19 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer0131-Jan-12 14:12
SledgeHammer0131-Jan-12 14:12 
GeneralRe: basic Winsock / IOCP / UDP question Pin
Jochen Arndt31-Jan-12 21:25
professionalJochen Arndt31-Jan-12 21:25 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer011-Feb-12 6:52
SledgeHammer011-Feb-12 6:52 
I think that is what I'm doing Smile | :) ... I am using the network notifications w/ IOCP though. So in my start up I do:

C++
m_hIOCompletionPort = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);

when I create the socket, I do:

C++
SOCKET socket = WSASocket(pAddrInfo->ai_family, pAddrInfo->ai_socktype, 0, NULL, 0, WSA_FLAG_OVERLAPPED);

if (bind(socket, pAddrInfo->ai_addr, pAddrInfo->ai_addrlen) == SOCKET_ERROR)
{
...
}

CreateIoCompletionPort((HANDLE)socket, m_hIOCompletionPort, (DWORD)pClientContext, 0);

// I have 8 worker threads in this case, post initial recv

for (int nIndex = 0; nIndex < m_nThreadCount; nIndex++)
{
	SOCKADDR_STORAGE addr;

	addr.ss_family = AF_UNSPEC;
	addr.__ss_align = 0;

	int nAddrLen = sizeof(SOCKADDR_STORAGE);

	DWORD dwBytesSent = 0;
	DWORD dwFlags = 0;

	char szBuffer[MAX_BUFFER_SIZE];
	ZeroMemory(szBuffer, sizeof(szBuffer));

	WSABUF wsaBuf;

	wsaBuf.buf = szBuffer;
	wsaBuf.len = sizeof(szBuffer);

	OVERLAPPED overlapped;
	ZeroMemory(&overlapped, sizeof(OVERLAPPED));

	int nResult = ::WSARecvFrom(socket, &wsaBuf, 1, &dwBytesSent, &dwFlags, (sockaddr*)&addr,
							&nAddrLen, &overlapped, NULL);

	int nError = WSAGetLastError();

        // nResult = 1, nError = IO_PENDING which is ok since no data has arrived yet 
}

// create the 8 worker threads now


The worker thread func looks like:

C++
	while (WaitForSingleObject(m_hShutdownEvent, 0) != WAIT_OBJECT_0)
	{
		CClientContext* pClientContext = NULL;
		OVERLAPPED* pOverlapped = NULL;
		DWORD dwBytesTransferred = 0;
		DWORD dwFlags = 0;
		WSABUF* pWSABUF = NULL;

		BOOL bReturn = GetQueuedCompletionStatus(m_hIOCompletionPort, &dwBytesTransferred,
												 (LPDWORD)&pClientContext, &pOverlapped, INFINITE);

  // if it got here, I'm assuming the data is in the buffer and ready to go, no?

						SOCKADDR_STORAGE from;
						int nFromLen = sizeof(SOCKADDR_STORAGE);
						memset(&from, 0, sizeof(SOCKADDR_STORAGE));

						int nBytesRecv = -1;

							nBytesRecv = WSARecvFrom(pClientContext->GetSocket(), pWSABUF, 1, &dwBytesTransferred,
													&dwFlags, (sockaddr*)&from, &nFromLen, pOverlapped, NULL);
						


						int j = WSAGetLastError();
						int k = 0;


// PROBLEM is here!! nBytesRecv is still -1 and WSAGetLastError() is still 997 :(. It is my understanding that GetQueuedCompletionStatus() will block until buffer is ready? That is how it works on TCP at least.
						}

}

GeneralRe: basic Winsock / IOCP / UDP question Pin
Jochen Arndt1-Feb-12 7:35
professionalJochen Arndt1-Feb-12 7:35 
GeneralRe: basic Winsock / IOCP / UDP question Pin
SledgeHammer011-Feb-12 7:53
SledgeHammer011-Feb-12 7:53 
GeneralRe: basic Winsock / IOCP / UDP question Pin
Jochen Arndt1-Feb-12 8:00
professionalJochen Arndt1-Feb-12 8:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.