Article View: borland.public.cppbuilder.internet.socket
Article #3806Re: Creating sockets
From: Jonathan Benedicto
Date: Fri, 29 Apr 2005 20:17
Date: Fri, 29 Apr 2005 20:17
63 lines
2940 bytes
2940 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:42727b69$1@newsgroups.borland.com...
>
> UpdateCompletionPort() is not a Win32 API function, so I assume it
> is one of
> your own. What does it look like?
PPER_SOCKET_CONTEXT UpdateCompletionPort(SOCKET sd, IO_OPERATION
ClientIo, bool bAddToList)
{
PPER_SOCKET_CONTEXT lpPerSocketContext;
lpPerSocketContext = CtxtAllocate(sd, ClientIo);
if( lpPerSocketContext == NULL )
return NULL;
g_hIOCP = CreateIoCompletionPort((HANDLE)sd, g_hIOCP,
(DWORD_PTR)lpPerSocketContext, 0);
if( g_hIOCP == NULL ) {
mycprintf("CreateIoCompletionPort() failed: %d\n",
GetLastError());
if(lpPerSocketContext->pIOContext)
xfree(lpPerSocketContext->pIOContext);
xfree(lpPerSocketContext);
return NULL;
}
if( bAddToList )
CtxtListAddTo(lpPerSocketContext);
if( g_bVerbose )
mycprintf("UpdateCompletionPort: Socket(%d) added to IOCP\n",
lpPerSocketContext->Socket);
return lpPerSocketContext;
}
> You should be checking for WSA_IO_PENDING, not ERROR_IO_PENDING.
I'll fix this, thank you.
> You are making the assumption that the "greeting" was already sent,
> without
> first waiting for the overlapped I/O to actually complete first.
I'll change this to "Send posted.".
> For that matter, why are you using overlapped I/O on your socket to
> begin
> with?
Because I'm building this server to handle 100's of simulatenous
connections.
> Also, just for the record, your use of exception handling is
> horrible in
> these code snippets of yours. You are leaking a lot of resources
> when you
> decide to throw your exceptions because you are not closing/freeing
> resources you allocated beforehand.
Thank you for this info. I'll fix that also.
Technical Details
Message-ID:
<42729648$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<42717e9e$1@newsgroups.borland.com> <42718c45$1@newsgroups.borland.com> <4271b145$1@newsgroups.borland.com> <4271c6a8$1@newsgroups.borland.com> <4272519f$1@newsgroups.borland.com> <42727b69$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,890efe40447445cf X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Jonathan Benedicto" <incorrect@no.server> Newsgroups: borland.public.cppbuilder.internet.socket References: <42717e9e$1@newsgroups.borland.com> <42718c45$1@newsgroups.borland.com> <4271b145$1@newsgroups.borland.com> <4271c6a8$1@newsgroups.borland.com> <4272519f$1@newsgroups.borland.com> <42727b69$1@newsgroups.borland.com> Subject: Re: Creating sockets Date: Fri, 29 Apr 2005 16:17:13 -0400 Lines: 65 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 69.158.104.124 Message-ID: <42729648$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1114805832 69.158.104.124 (29 Apr 2005 13:17:12 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail