Home » U++ Library support » U++ MT-multithreading and servers » TcpSocket in Array
TcpSocket in Array [message #37216] |
Thu, 06 September 2012 15:41 |
Zbych
Messages: 325 Registered: July 2009
|
Senior Member |
|
|
Hi,
In my application I would like to keep all open sockets in an Array. The problem is that when I add (or maybe I should say 'move') TcpSocket to Array and TcpSocket gets out of scope, program crashes. Destructor tries to call ssl->Close() and ssl pointer has value 1.
CONSOLE_APP_MAIN
{
Array<TcpSocket> a;
{
TcpSocket s;
a.Add(s);
}//<---- crash
//rest of code that uses TcpSockets collected in Array
}
The question is how should I add TcpSockets to Array to avoid this error?
|
|
|
|
|
Re: TcpSocket in Array [message #37220 is a reply to message #37218] |
Thu, 06 September 2012 19:11 |
omari
Messages: 265 Registered: March 2010
|
Experienced Member |
|
|
CONSOLE_APP_MAIN
{
Array<TcpSocket> a;
{
TcpSocket s;
if(..)
a.Add() = s;
}
}
Note: the destructor TCPSocket can cause problems.
if this is the case, I recomande the first solution:
CONSOLE_APP_MAIN
{
Array<TcpSocket> a;
{
TcpSocket& s = a.Add();
if (! ..)
a.Remove(a.GetCount()-1);
}
}
regards
omari.
[Updated on: Thu, 06 September 2012 19:35] Report message to a moderator
|
|
|
|
|
Goto Forum:
Current Time: Tue Apr 23 23:29:23 CEST 2024
Total time taken to generate the page: 0.03003 seconds
|