From: Joel on
Hi,
I have a serious probleme with my CSocket.
I have a thread that is using a CSocket to send and receive data.
I use the Attach/detach function to put my socket in the thread.
All works wonderfully .... 97% of the time.
Sometimes, when i really try to make my application crash (by sending many
datas with Send) the i got the assertion in the following function

BOOL CSocket::PumpMessages(UINT uStopFlag)

{

<snip>

ASSERT(pState->m_hSocketWindow != NULL); // << Assertion here



I read so many post speaking about this problem ....

but my case is specific:

- My socket work perfectly (97% of the time)

- problem doesn't occur on the first send.

- i did an AfxSocketInit at the starting of my thread



I'd be really gratefull if someone has an idea of what is wrong with that
....



Thx



Joel


From: Joseph M. Newcomer on
Using CSocket is a Really Bad Idea. Not only are synchronous sockets Bad Ideas, but the
rumor is that the CSocket implementation has bugs. Rewrite your code to use CAsyncSocket.

Is your thread a UI thread? If it is not a UI thread, no socket can work.
joe

On Fri, 25 Feb 2005 16:41:35 +0100, "Joel" <nospam(a)nospam.com> wrote:

>Hi,
>I have a serious probleme with my CSocket.
>I have a thread that is using a CSocket to send and receive data.
>I use the Attach/detach function to put my socket in the thread.
>All works wonderfully .... 97% of the time.
>Sometimes, when i really try to make my application crash (by sending many
>datas with Send) the i got the assertion in the following function
>
>BOOL CSocket::PumpMessages(UINT uStopFlag)
>
>{
>
><snip>
>
>ASSERT(pState->m_hSocketWindow != NULL); // << Assertion here
>
>
>
>I read so many post speaking about this problem ....
>
>but my case is specific:
>
>- My socket work perfectly (97% of the time)
>
>- problem doesn't occur on the first send.
>
>- i did an AfxSocketInit at the starting of my thread
>
>
>
>I'd be really gratefull if someone has an idea of what is wrong with that
>...
>
>
>
>Thx
>
>
>
>Joel
>

Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Crosoft on
"Joseph M. Newcomer" <newcomer(a)flounder.com> a ýcrit dans le message de
news: eqqu119a6c9021107ifuajlf305jpgo0tc(a)4ax.com...
> Using CSocket is a Really Bad Idea. Not only are synchronous sockets Bad
Ideas, but the
> rumor is that the CSocket implementation has bugs. Rewrite your code to
use CAsyncSocket.
>
> Is your thread a UI thread? If it is not a UI thread, no socket can work.

CWinThread ....

From: Joseph M. Newcomer on
With a CWinThread there are a couple issues about how it is created. For example,
AfxBeginThread(threadfunc, parameter) returns a CWinThread object, but does not create a
UI thread. I've also see AfxBeginThread done on a CWinThread-derived subclass but all the
work is done in an infinite loop in InitInstance, which means there is no functioning
message pump. Let me rephrase it: you have to have a UI thread with a functioning message
pump for a socket to work at all. But CSocket is really risky. I never used one, so I
can't attest to the claims that the implementation is buggy, but there are so many
fundamental problems with synchronous sockets as a communication mechanism (even if they
worked properly) that I would never use one.
joe

On Sat, 26 Feb 2005 16:08:31 +0100, "Crosoft" <trash(a)trash.fr> wrote:

>"Joseph M. Newcomer" <newcomer(a)flounder.com> a ýcrit dans le message de
>news: eqqu119a6c9021107ifuajlf305jpgo0tc(a)4ax.com...
>> Using CSocket is a Really Bad Idea. Not only are synchronous sockets Bad
>Ideas, but the
>> rumor is that the CSocket implementation has bugs. Rewrite your code to
>use CAsyncSocket.
>>
>> Is your thread a UI thread? If it is not a UI thread, no socket can work.
>
>CWinThread ....

Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joel on
Ok thanks for help...

Let see how i do:

To launch my thread:
TacheEcoute* tacheEc = (TacheEcoute*) // This is my CWinThread

AfxBeginThread(RUNTIME_CLASS(TacheEcoute), THREAD_PRIORITY_NORMAL, 0,
CREATE_SUSPENDED);

tacheEc->setSocket(s.Detach());

tacheEc->ResumeThread();



I have an infinite loop in my ::Run() function


And my pumpmessage definitivly don t work. I crash the first time I do it
(but I need to overload my app to have to do it).


Do you see what am I doing wrong ?

Thanks again for help.

Joel


"Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message
news:d6l42198eq59lfecjjkmolh2qgleh1p4va(a)4ax.com...
> With a CWinThread there are a couple issues about how it is created. For
example,
> AfxBeginThread(threadfunc, parameter) returns a CWinThread object, but
does not create a
> UI thread. I've also see AfxBeginThread done on a CWinThread-derived
subclass but all the
> work is done in an infinite loop in InitInstance, which means there is no
functioning
> message pump. Let me rephrase it: you have to have a UI thread with a
functioning message
> pump for a socket to work at all. But CSocket is really risky. I never
used one, so I
> can't attest to the claims that the implementation is buggy, but there are
so many
> fundamental problems with synchronous sockets as a communication mechanism
(even if they
> worked properly) that I would never use one.
> joe
>
> On Sat, 26 Feb 2005 16:08:31 +0100, "Crosoft" <trash(a)trash.fr> wrote:
>
> >"Joseph M. Newcomer" <newcomer(a)flounder.com> a ýcrit dans le message de
> >news: eqqu119a6c9021107ifuajlf305jpgo0tc(a)4ax.com...
> >> Using CSocket is a Really Bad Idea. Not only are synchronous sockets
Bad
> >Ideas, but the
> >> rumor is that the CSocket implementation has bugs. Rewrite your code to
> >use CAsyncSocket.
> >>
> >> Is your thread a UI thread? If it is not a UI thread, no socket can
work.
> >
> >CWinThread ....
>
> Joseph M. Newcomer [MVP]
> email: newcomer(a)flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm