| 1 |
|
| 2 |
#include "protokit.h" |
| 3 |
#include "protoList.h" |
| 4 |
#include <stdio.h> // for stderr output as needed |
| 5 |
#include <stdlib.h> // for atoi() |
| 6 |
|
| 7 |
#define PIPE_TYPE ProtoPipe::MESSAGE |
| 8 |
|
| 9 |
/** |
| 10 |
* @class Msg2Msg |
| 11 |
* |
| 12 |
* @brief This example program illustrates/tests the use of the ProtoPipe class |
| 13 |
* for local domain interprocess communications |
| 14 |
*/ |
| 15 |
class Msg2Msg : public ProtoApp |
| 16 |
{ |
| 17 |
public: |
| 18 |
Msg2Msg(); |
| 19 |
~Msg2Msg(); |
| 20 |
|
| 21 |
// Overrides from ProtoApp or NsProtoSimAgent base |
| 22 |
bool OnStartup(int argc, const char*const* argv); |
| 23 |
void OnShutdown(); |
| 24 |
bool ProcessCommands(int argc, const char*const* argv); |
| 25 |
bool AddNewRcvPipe(const char* pipeName); |
| 26 |
bool AddNewSndPipe(const char* pipeName); |
| 27 |
bool AddNewRcvSocket(const char* socketAddrStr); |
| 28 |
bool AddNewSndSocket(const char* socketAddrStr); |
| 29 |
bool AddNewSndFile(const char* fileName); |
| 30 |
|
| 31 |
private: |
| 32 |
enum CmdType {CMD_INVALID, CMD_ARG, CMD_NOARG}; |
| 33 |
static CmdType GetCmdType(const char* string); |
| 34 |
static const char* const CMD_LIST[]; |
| 35 |
void Usage(); |
| 36 |
|
| 37 |
void OnSocketListenEvent(ProtoSocket& theSocket, |
| 38 |
ProtoSocket::Event theEvent); |
| 39 |
void OnPipeListenEvent(ProtoSocket& thePipe, |
| 40 |
ProtoSocket::Event theEvent); |
| 41 |
//void OnSdtinTimeout(); |
| 42 |
|
| 43 |
void SendMessage(); |
| 44 |
|
| 45 |
class ListableSocket : public ProtoSocket, public ProtoList::Item |
| 46 |
{ |
| 47 |
public: |
| 48 |
ListableSocket(ProtoSocket::Protocol theprotocol) : ProtoSocket(theprotocol = ProtoSocket::UDP) {} |
| 49 |
}; |
| 50 |
class ListablePipe : public ProtoPipe, public ProtoList::Item |
| 51 |
{ |
| 52 |
public: |
| 53 |
ListablePipe(ProtoPipe::Type thetype) : ProtoPipe(thetype) {} |
| 54 |
}; |
| 55 |
class ListableFile : public ProtoFile, public ProtoList::Item{}; |
| 56 |
|
| 57 |
class SocketList : public ProtoListTemplate<ListableSocket> {}; |
| 58 |
class PipeList : public ProtoListTemplate<ListablePipe> {}; |
| 59 |
class FileList : public ProtoListTemplate<ListableFile> {}; |
| 60 |
SocketList sndSockets; |
| 61 |
SocketList rcvSockets; |
| 62 |
PipeList sndPipes; |
| 63 |
PipeList rcvPipes; |
| 64 |
FileList sndFiles; |
| 65 |
bool usingstdout; |
| 66 |
|
| 67 |
bool usingstdin; |
| 68 |
ProtoTimer sdtinTimer; //used for checking if anything is in sdtin |
| 69 |
ProtoTimerMgr *timerMgrPtr; |
| 70 |
|
| 71 |
char msg_buffer[8191]; |
| 72 |
unsigned int msg_len; |
| 73 |
}; // end class Msg2Msg |
| 74 |
|
| 75 |
// Instantiate our application instance |
| 76 |
PROTO_INSTANTIATE_APP(Msg2Msg) |
| 77 |
|
| 78 |
Msg2Msg::Msg2Msg() |
| 79 |
: usingstdout(false), usingstdin(false), msg_len(8191) |
| 80 |
{ |
| 81 |
memset(msg_buffer,0,8191); |
| 82 |
} |
| 83 |
|
| 84 |
Msg2Msg::~Msg2Msg() |
| 85 |
{ |
| 86 |
} |
| 87 |
|
| 88 |
void Msg2Msg::Usage() |
| 89 |
{ |
| 90 |
fprintf(stderr, "msg2Msg [listen pipe <listenName>]\n"); |
| 91 |
fprintf(stderr, " [listen socket <mcastAddr>/]<port>\n"); |
| 92 |
fprintf(stderr, " [listen stdin]\n"); |
| 93 |
fprintf(stderr, " [send pipe <sendName>]\n"); |
| 94 |
fprintf(stderr, " [send socket <ipaddress>/<dst_port>]\n"); |
| 95 |
fprintf(stderr, " [send file <filepath>]\n"); |
| 96 |
fprintf(stderr, " [send sdtout>]\n"); |
| 97 |
} // end Msg2Msg::Usage() |
| 98 |
|
| 99 |
bool Msg2Msg::OnStartup(int argc, const char*const* argv) |
| 100 |
{ |
| 101 |
if (argc == 1) |
| 102 |
{ |
| 103 |
TRACE("No args! Are you sure you want to be running without any args?\n"); |
| 104 |
Usage(); |
| 105 |
} |
| 106 |
if (!ProcessCommands(argc, argv)) |
| 107 |
{ |
| 108 |
PLOG(PL_ERROR, "msg2Msg::OnStartup() error processing command line\n"); |
| 109 |
Usage(); |
| 110 |
return false; |
| 111 |
} |
| 112 |
return true; |
| 113 |
} // end Msg2Msg::OnStartup() |
| 114 |
|
| 115 |
void Msg2Msg::OnShutdown() |
| 116 |
{ |
| 117 |
//we have to close this stuff; |
| 118 |
ListableSocket* sndSocketPtr = NULL; |
| 119 |
while(!sndSockets.IsEmpty())//close out the socket |
| 120 |
{ |
| 121 |
sndSocketPtr = sndSockets.RemoveHead(); |
| 122 |
if(sndSocketPtr->IsOpen()) sndSocketPtr->Close(); |
| 123 |
delete sndSocketPtr; |
| 124 |
} |
| 125 |
|
| 126 |
ListableSocket* rcvSocketPtr = NULL; |
| 127 |
while(!rcvSockets.IsEmpty())//close out the socket |
| 128 |
{ |
| 129 |
rcvSocketPtr = rcvSockets.RemoveHead(); |
| 130 |
if(rcvSocketPtr->IsOpen()) rcvSocketPtr->Close(); |
| 131 |
delete rcvSocketPtr; |
| 132 |
} |
| 133 |
|
| 134 |
ListablePipe* sndPipePtr = NULL; |
| 135 |
while(!sndPipes.IsEmpty())//close out the pipe |
| 136 |
{ |
| 137 |
sndPipePtr = sndPipes.RemoveHead(); |
| 138 |
if(sndPipePtr->IsOpen()) sndPipePtr->Close(); |
| 139 |
delete sndPipePtr; |
| 140 |
} |
| 141 |
|
| 142 |
ListablePipe* rcvPipePtr = NULL; |
| 143 |
while(!rcvPipes.IsEmpty())//close out the pipe |
| 144 |
{ |
| 145 |
rcvPipePtr = rcvPipes.RemoveHead(); |
| 146 |
if(rcvPipePtr->IsOpen()) rcvPipePtr->Close(); |
| 147 |
delete rcvPipePtr; |
| 148 |
} |
| 149 |
|
| 150 |
ListableFile* sndFilePtr = NULL; |
| 151 |
while(!sndFiles.IsEmpty())//close out the file |
| 152 |
{ |
| 153 |
sndFilePtr = sndFiles.RemoveHead(); |
| 154 |
if(sndFilePtr->IsOpen()) sndFilePtr->Close(); |
| 155 |
delete sndFilePtr; |
| 156 |
} |
| 157 |
|
| 158 |
if(usingstdin) |
| 159 |
{ |
| 160 |
//do nothing |
| 161 |
} |
| 162 |
if(usingstdout) |
| 163 |
{ |
| 164 |
//do nothing |
| 165 |
} |
| 166 |
TRACE("msg2Msg: Done.\n"); |
| 167 |
} // end Msg2Msg::OnShutdown() |
| 168 |
|
| 169 |
void Msg2Msg::OnPipeListenEvent(ProtoSocket& theSocket, |
| 170 |
ProtoSocket::Event theEvent) |
| 171 |
{ |
| 172 |
ProtoPipe *thePipePtr = (ProtoPipe*)&theSocket; |
| 173 |
switch (theEvent) |
| 174 |
{ |
| 175 |
case ProtoSocket::RECV: |
| 176 |
{ |
| 177 |
TRACE("msg2Msg: listen RECV event ..\n"); |
| 178 |
unsigned int len = 8191; |
| 179 |
if(thePipePtr->Recv(msg_buffer, len)) |
| 180 |
{ |
| 181 |
if(len) |
| 182 |
{ |
| 183 |
SendMessage(); |
| 184 |
} |
| 185 |
} |
| 186 |
else |
| 187 |
{ |
| 188 |
DMSG(0,"Msg2Msg::OnPipeListenEvent() Error getting message\n"); |
| 189 |
} |
| 190 |
break; |
| 191 |
} |
| 192 |
case ProtoSocket::SEND: |
| 193 |
TRACE("msg2Msg: listen SEND event ..\n"); |
| 194 |
break; |
| 195 |
case ProtoSocket::ACCEPT: |
| 196 |
TRACE("msg2Msg: listen ACCEPT event ..\n"); |
| 197 |
if(!thePipePtr->Accept()) |
| 198 |
{ |
| 199 |
DMSG(0,"Msg2Msg::OnPipeListenEvent() Error on calling Accept()\n"); |
| 200 |
} |
| 201 |
break; |
| 202 |
case ProtoSocket::DISCONNECT: |
| 203 |
TRACE("msg2Msg: listen DISCONNECT event ..\n"); |
| 204 |
char pipeName[PATH_MAX]; |
| 205 |
strncpy(pipeName,thePipePtr->GetName(),PATH_MAX); |
| 206 |
thePipePtr->Close(); |
| 207 |
if(!thePipePtr->Listen(pipeName)) |
| 208 |
{ |
| 209 |
DMSG(0,"Msg2Msg::OnPipeListenEvent() Error restarting listen pipe...\n"); |
| 210 |
} |
| 211 |
break; |
| 212 |
default: |
| 213 |
TRACE("Msg2Msg::OnPipeListenEvent(%d) unhandled event type\n", theEvent); |
| 214 |
break; |
| 215 |
|
| 216 |
} // end switch(theEvent) |
| 217 |
} // end Msg2Msg::OnPipeListenEvent() |
| 218 |
|
| 219 |
void Msg2Msg::OnSocketListenEvent(ProtoSocket& theSocket, |
| 220 |
ProtoSocket::Event theEvent) |
| 221 |
{ |
| 222 |
switch (theEvent) |
| 223 |
{ |
| 224 |
case ProtoSocket::RECV: |
| 225 |
{ |
| 226 |
TRACE("msg2Msg: listen RECV event ..\n"); |
| 227 |
unsigned int len = 8191; |
| 228 |
if(theSocket.Recv(msg_buffer, len)) |
| 229 |
{ |
| 230 |
if(len) |
| 231 |
{ |
| 232 |
SendMessage(); |
| 233 |
} |
| 234 |
} |
| 235 |
else |
| 236 |
{ |
| 237 |
DMSG(0,"Msg2Msg::OnSocketListenEvent() Error getting message\n"); |
| 238 |
} |
| 239 |
break; |
| 240 |
} |
| 241 |
case ProtoSocket::SEND: |
| 242 |
TRACE("msg2Msg: listen SEND event ..\n"); |
| 243 |
break; |
| 244 |
case ProtoSocket::ACCEPT: |
| 245 |
TRACE("msg2Msg: listen ACCEPT event ..\n"); |
| 246 |
break; |
| 247 |
case ProtoSocket::DISCONNECT: |
| 248 |
TRACE("msg2Msg: listen DISCONNECT event ..\n"); |
| 249 |
break; |
| 250 |
default: |
| 251 |
TRACE("Msg2Msg::OnSocketListenEvent(%d) unhandled event type\n", theEvent); |
| 252 |
break; |
| 253 |
|
| 254 |
} // end switch(theEvent) |
| 255 |
} // end Msg2Msg::OnSocketListenEvent() |
| 256 |
|
| 257 |
void Msg2Msg::SendMessage() |
| 258 |
{ |
| 259 |
unsigned int len = strlen(msg_buffer); |
| 260 |
|
| 261 |
SocketList::Iterator socketIterator(sndSockets); |
| 262 |
ListableSocket* sndSocketPtr = NULL; |
| 263 |
while((sndSocketPtr = socketIterator.GetNextItem()))//close out the socket |
| 264 |
{ |
| 265 |
if(sndSocketPtr->IsOpen()) |
| 266 |
{ |
| 267 |
sndSocketPtr->Send(msg_buffer,len); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
PipeList::Iterator pipeIterator(sndPipes); |
| 272 |
ListablePipe* sndPipePtr = NULL; |
| 273 |
while((sndPipePtr = pipeIterator.GetNextItem()))//close out the pipe |
| 274 |
{ |
| 275 |
if(sndPipePtr->IsOpen()) |
| 276 |
{ |
| 277 |
sndPipePtr->Send(msg_buffer,len); |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
FileList::Iterator fileIterator(sndFiles); |
| 282 |
ListableFile* sndFilePtr = NULL; |
| 283 |
while((sndFilePtr = fileIterator.GetNextItem()))//close out the file |
| 284 |
{ |
| 285 |
if(sndFilePtr->IsOpen()) |
| 286 |
{ |
| 287 |
sndFilePtr->Write(msg_buffer,len); |
| 288 |
} |
| 289 |
} |
| 290 |
if(usingstdout) |
| 291 |
{ |
| 292 |
fprintf(stdout,"%s\n",msg_buffer); |
| 293 |
} |
| 294 |
memset(msg_buffer,0,msg_len); //clear out the message |
| 295 |
} |
| 296 |
|
| 297 |
bool Msg2Msg::ProcessCommands(int argc, const char*const* argv) |
| 298 |
{ |
| 299 |
int i = 1; |
| 300 |
while ( i < argc) |
| 301 |
{ |
| 302 |
if (!strcmp("listen", argv[i])) |
| 303 |
{ |
| 304 |
i++; |
| 305 |
if(!strcmp("pipe",argv[i])) |
| 306 |
{ |
| 307 |
i++; |
| 308 |
AddNewRcvPipe(argv[i]); |
| 309 |
} |
| 310 |
else if (!strcmp("socket",argv[i])) |
| 311 |
{ |
| 312 |
i++; |
| 313 |
AddNewRcvSocket(argv[i]); |
| 314 |
} |
| 315 |
else if (!strcmp("sdtin",argv[i])) |
| 316 |
{ |
| 317 |
usingstdin = true; |
| 318 |
//install timer loop |
| 319 |
//bunny fix this to actually open stdin |
| 320 |
} |
| 321 |
else |
| 322 |
{ |
| 323 |
DMSG(0,"Msg2Msg::ProcessCommands() Error setting listen to type %s\n",argv[i]); |
| 324 |
} |
| 325 |
} |
| 326 |
else if (!strcmp("send", argv[i])) |
| 327 |
{ |
| 328 |
i++; |
| 329 |
if(!strcmp("pipe",argv[i])) |
| 330 |
{ |
| 331 |
i++; |
| 332 |
AddNewSndPipe(argv[i]); |
| 333 |
} |
| 334 |
else if (!strcmp("socket",argv[i])) |
| 335 |
{ |
| 336 |
i++; |
| 337 |
AddNewSndSocket(argv[i]); |
| 338 |
} |
| 339 |
else if (!strcmp("file",argv[i])) |
| 340 |
{ |
| 341 |
i++; |
| 342 |
AddNewSndFile(argv[i]); |
| 343 |
} |
| 344 |
else if (!strcmp("sdtout",argv[i])) |
| 345 |
{ |
| 346 |
usingstdin = true; |
| 347 |
} |
| 348 |
else |
| 349 |
{ |
| 350 |
DMSG(0,"Msg2Msg::ProcessCommands() Error setting send to type %s\n",argv[i]); |
| 351 |
} |
| 352 |
} |
| 353 |
else |
| 354 |
{ |
| 355 |
PLOG(PL_ERROR, "Msg2Msg::ProcessCommand() unknown command error?\n"); |
| 356 |
return false; |
| 357 |
} |
| 358 |
i++; |
| 359 |
} |
| 360 |
return true; |
| 361 |
} // end Msg2Msg::ProcessCommands() |
| 362 |
bool |
| 363 |
Msg2Msg::AddNewRcvPipe(const char* pipeName) |
| 364 |
{ |
| 365 |
ListablePipe *newPipePtr = new ListablePipe(ProtoPipe::MESSAGE); |
| 366 |
if(!newPipePtr) |
| 367 |
{ |
| 368 |
DMSG(0,"Msg2MsgAddNewRcvPipe error allocing new pipe\n"); |
| 369 |
return false; |
| 370 |
} |
| 371 |
newPipePtr->SetNotifier(&GetSocketNotifier()); |
| 372 |
newPipePtr->SetListener(this,&Msg2Msg::OnPipeListenEvent);//bunny the this will need to be changed |
| 373 |
if(!newPipePtr->Listen(pipeName)) |
| 374 |
{ |
| 375 |
DMSG(0,"Msg2Msg::AddNewRcvPipe: Error opening pipe to %s\n",pipeName); |
| 376 |
delete newPipePtr; |
| 377 |
return false; |
| 378 |
} |
| 379 |
rcvPipes.Append(*newPipePtr); |
| 380 |
return true; |
| 381 |
} |
| 382 |
bool |
| 383 |
Msg2Msg::AddNewSndPipe(const char* pipeName) |
| 384 |
{ |
| 385 |
ListablePipe *newPipePtr = new ListablePipe(ProtoPipe::MESSAGE); |
| 386 |
if(!newPipePtr) |
| 387 |
{ |
| 388 |
DMSG(0,"Msg2MsgAddNewSndPipe error allocing new pipe\n"); |
| 389 |
return false; |
| 390 |
} |
| 391 |
if(!newPipePtr->Connect(pipeName)) |
| 392 |
{ |
| 393 |
DMSG(0,"Msg2Msg::AddNewRcvPipe: Error connecting pipe to %s\n",pipeName); |
| 394 |
delete newPipePtr; |
| 395 |
return false; |
| 396 |
} |
| 397 |
sndPipes.Append(*newPipePtr); |
| 398 |
return true; |
| 399 |
} |
| 400 |
bool |
| 401 |
Msg2Msg::AddNewRcvSocket(const char* socketAddrStr) |
| 402 |
{ |
| 403 |
char charAddr[255]; |
| 404 |
memset(charAddr,0,255); |
| 405 |
ProtoAddress rcv_addr; |
| 406 |
int rcv_port; |
| 407 |
//parse socketAddrStr |
| 408 |
const char* index = strchr(socketAddrStr,'/'); |
| 409 |
if(index!=NULL) |
| 410 |
{ |
| 411 |
strncpy(charAddr,socketAddrStr,index-socketAddrStr); |
| 412 |
if(!(rcv_addr.ResolveFromString(charAddr))) |
| 413 |
{ |
| 414 |
DMSG(0,"Msg2Msg::AddNewRcvSocket() Error setting address to %s\n",charAddr); |
| 415 |
return false; |
| 416 |
} |
| 417 |
rcv_port = atoi(index+1); |
| 418 |
} |
| 419 |
else |
| 420 |
{ |
| 421 |
rcv_port = atoi(socketAddrStr); |
| 422 |
} |
| 423 |
ListableSocket *newSocketPtr = new ListableSocket(ProtoPipe::UDP); |
| 424 |
if(!newSocketPtr) |
| 425 |
{ |
| 426 |
DMSG(0,"Msg2MsgAddNewRcvSocket error allocing new socket\n"); |
| 427 |
return false; |
| 428 |
} |
| 429 |
newSocketPtr->SetNotifier(&GetSocketNotifier()); |
| 430 |
newSocketPtr->SetListener(this,&Msg2Msg::OnSocketListenEvent);//bunny the this will need to be changed |
| 431 |
if(!(newSocketPtr->Open(rcv_port,ProtoAddress::IPv4))) |
| 432 |
{ |
| 433 |
DMSG(0,"Msg2MsgAddNewRcvSocket Error Opening the socket rcv port %d\n",rcv_port); |
| 434 |
delete newSocketPtr; |
| 435 |
return false; |
| 436 |
} |
| 437 |
if(rcv_addr.IsMulticast()) //do multicast stuff |
| 438 |
{ |
| 439 |
if(!newSocketPtr->JoinGroup(rcv_addr)) |
| 440 |
{ |
| 441 |
DMSG(0,"Msg2MsgAddNewRcvSocket Error joining the multicast group %s\n",rcv_addr.GetHostString()); |
| 442 |
newSocketPtr->Close(); |
| 443 |
delete newSocketPtr; |
| 444 |
return false; |
| 445 |
} |
| 446 |
} |
| 447 |
rcvSockets.Append(*newSocketPtr); |
| 448 |
return true; |
| 449 |
} |
| 450 |
bool |
| 451 |
Msg2Msg::AddNewSndSocket(const char* socketAddrStr) |
| 452 |
{ |
| 453 |
char charAddr[255]; |
| 454 |
memset(charAddr,0,255); |
| 455 |
ProtoAddress dst_addr; |
| 456 |
int dst_port; |
| 457 |
int src_port;//bunny setting this to dst port for now this should be controled seperatly |
| 458 |
//parse the string |
| 459 |
const char* index = strchr(socketAddrStr,'/'); |
| 460 |
if(index!=NULL) |
| 461 |
{ |
| 462 |
strncpy(charAddr,socketAddrStr,index-socketAddrStr); |
| 463 |
if(!dst_addr.ResolveFromString(charAddr)) |
| 464 |
{ |
| 465 |
DMSG(0,"Msg2Msg::AddNewSndSocket: Error setting address to %s\n",socketAddrStr); |
| 466 |
return false; |
| 467 |
} |
| 468 |
dst_port = atoi(index+1); |
| 469 |
src_port = dst_port; |
| 470 |
dst_addr.SetPort(dst_port); |
| 471 |
} |
| 472 |
else |
| 473 |
{ |
| 474 |
DMSG(0,"Msg2Msg::AddNewSndSocket: Error missing \"/\" for send socket command\n"); |
| 475 |
return false; |
| 476 |
} |
| 477 |
ListableSocket *newSocketPtr = new ListableSocket(ProtoSocket::UDP); |
| 478 |
if(!newSocketPtr) |
| 479 |
{ |
| 480 |
DMSG(0,"Msg2MsgAddNewSndSocket error allocing new socket\n"); |
| 481 |
return false; |
| 482 |
} |
| 483 |
if(!(newSocketPtr->Bind(src_port))) |
| 484 |
{ |
| 485 |
DMSG(0,"Msg2MsgAddNewSndSocket: Error binding to src_port %d\n",src_port); |
| 486 |
delete newSocketPtr; |
| 487 |
return false; |
| 488 |
} |
| 489 |
if(!(newSocketPtr->Open(src_port,ProtoAddress::IPv4,false))) |
| 490 |
{ |
| 491 |
DMSG(0,"msg2MsgAddNewSndSocket: Error opening socket on port %d\n",src_port); |
| 492 |
delete newSocketPtr; |
| 493 |
return false; |
| 494 |
} |
| 495 |
if(dst_addr.IsMulticast()) |
| 496 |
{ |
| 497 |
if(!newSocketPtr->JoinGroup(dst_addr)) |
| 498 |
{ |
| 499 |
DMSG(0,"Msg2MsgAddNewSndSocket: Error joinging multicast Group %s\n",dst_addr.GetHostString()); |
| 500 |
newSocketPtr->Close(); |
| 501 |
delete newSocketPtr; |
| 502 |
return false; |
| 503 |
} |
| 504 |
} |
| 505 |
if(!(newSocketPtr->Connect(dst_addr))) |
| 506 |
{ |
| 507 |
DMSG(0,"Msg2MsgAddNewSndSocket: Error connecting to %s\n",dst_addr.GetHostString()); |
| 508 |
newSocketPtr->Close(); |
| 509 |
delete newSocketPtr; |
| 510 |
return false; |
| 511 |
} |
| 512 |
sndSockets.Append(*newSocketPtr); |
| 513 |
return true; |
| 514 |
} |
| 515 |
bool |
| 516 |
Msg2Msg::AddNewSndFile(const char* fileName) |
| 517 |
{ |
| 518 |
ListableFile *newFilePtr = new ListableFile(); |
| 519 |
if(!newFilePtr) |
| 520 |
{ |
| 521 |
DMSG(0,"Msg2MsgAddNewSndSocket error allocing new socket\n"); |
| 522 |
return false; |
| 523 |
} |
| 524 |
if(!(newFilePtr->Open(fileName,O_WRONLY | O_CREAT))) |
| 525 |
{ |
| 526 |
DMSG(0,"Msg2MsgAddNewSndFile error opening the file \"%s\"\n",fileName); |
| 527 |
delete newFilePtr; |
| 528 |
return false; |
| 529 |
} |
| 530 |
sndFiles.Append(*newFilePtr); |
| 531 |
return true; |
| 532 |
} |