groupsock/Groupsock.cpp File Reference

#include "Groupsock.hh"
#include "GroupsockHelper.hh"
#include "TunnelEncaps.hh"
#include <sstream>
#include <stdio.h>

Include dependency graph for Groupsock.cpp:

Go to the source code of this file.

Functions

UsageEnvironmentoperator<< (UsageEnvironment &s, const Groupsock &g)
static HashTable *& getSocketTable (UsageEnvironment &env)
static Boolean unsetGroupsockBySocket (Groupsock const *groupsock)
static Boolean setGroupsockBySocket (UsageEnvironment &env, int sock, Groupsock *groupsock)
static GroupsockgetGroupsockBySocket (UsageEnvironment &env, int sock)


Function Documentation

static Groupsock* getGroupsockBySocket ( UsageEnvironment env,
int  sock 
) [static]

Definition at line 529 of file Groupsock.cpp.

References Socket::env(), getSocketTable(), HashTable::Lookup(), and NULL.

Referenced by GroupsockLookupTable::Lookup().

00529                                                                         {
00530   do {
00531     // Make sure the "sock" parameter is in bounds:
00532     if (sock < 0) break;
00533 
00534     HashTable* sockets = getSocketTable(env);
00535     return (Groupsock*)sockets->Lookup((char*)(long)sock);
00536   } while (0);
00537 
00538   return NULL;
00539 }

static HashTable*& getSocketTable ( UsageEnvironment env  )  [static]

Definition at line 463 of file Groupsock.cpp.

References HashTable::create(), Socket::env(), groupsockPriv(), NULL, ONE_WORD_HASH_KEYS, and _groupsockPriv::socketTable.

Referenced by getGroupsockBySocket(), setGroupsockBySocket(), and unsetGroupsockBySocket().

00463                                                          {
00464   _groupsockPriv* priv = groupsockPriv(env);
00465   if (priv->socketTable == NULL) { // We need to create it
00466     priv->socketTable = HashTable::create(ONE_WORD_HASH_KEYS);
00467   }
00468   return priv->socketTable;
00469 }

UsageEnvironment& operator<< ( UsageEnvironment s,
const Groupsock g 
)

Definition at line 444 of file Groupsock.cpp.

00444                                                                       {
00445   UsageEnvironment& s1 = s << timestampString() << " Groupsock("
00446                            << g.socketNum() << ": "
00447                            << AddressString(g.groupAddress()).val()
00448                            << ", " << g.port() << ", ";
00449   if (g.isSSM()) {
00450     return s1 << "SSM source: "
00451               <<  AddressString(g.sourceFilterAddress()).val() << ")";
00452   } else {
00453     return s1 << (unsigned)(g.ttl()) << ")";
00454   }
00455 }

static Boolean setGroupsockBySocket ( UsageEnvironment env,
int  sock,
Groupsock groupsock 
) [static]

Definition at line 497 of file Groupsock.cpp.

References HashTable::Add(), Socket::env(), False, getSocketTable(), HashTable::Lookup(), UsageEnvironment::setResultMsg(), and True.

Referenced by GroupsockLookupTable::AddNew().

00498                                                           {
00499   do {
00500     // Make sure the "sock" parameter is in bounds:
00501     if (sock < 0) {
00502       char buf[100];
00503       sprintf(buf, "trying to use bad socket (%d)", sock);
00504       env.setResultMsg(buf);
00505       break;
00506     }
00507 
00508     HashTable* sockets = getSocketTable(env);
00509 
00510     // Make sure we're not replacing an existing Groupsock (although that shouldn't happen)
00511     Boolean alreadyExists
00512       = (sockets->Lookup((char*)(long)sock) != 0);
00513     if (alreadyExists) {
00514       char buf[100];
00515       sprintf(buf,
00516               "Attempting to replace an existing socket (%d",
00517               sock);
00518       env.setResultMsg(buf);
00519       break;
00520     }
00521 
00522     sockets->Add((char*)(long)sock, groupsock);
00523     return True;
00524   } while (0);
00525 
00526   return False;
00527 }

static Boolean unsetGroupsockBySocket ( Groupsock const *  groupsock  )  [static]

Definition at line 471 of file Groupsock.cpp.

References Socket::env(), False, getSocketTable(), HashTable::IsEmpty(), HashTable::Lookup(), NULL, reclaimGroupsockPriv(), HashTable::Remove(), Socket::socketNum(), and True.

Referenced by GroupsockLookupTable::Remove().

00471                                                                   {
00472   do {
00473     if (groupsock == NULL) break;
00474 
00475     int sock = groupsock->socketNum();
00476     // Make sure "sock" is in bounds:
00477     if (sock < 0) break;
00478 
00479     HashTable*& sockets = getSocketTable(groupsock->env());
00480 
00481     Groupsock* gs = (Groupsock*)sockets->Lookup((char*)(long)sock);
00482     if (gs == NULL || gs != groupsock) break;
00483     sockets->Remove((char*)(long)sock);
00484 
00485     if (sockets->IsEmpty()) {
00486       // We can also delete the table (to reclaim space):
00487       delete sockets; sockets = NULL;
00488       reclaimGroupsockPriv(gs->env());
00489     }
00490 
00491     return True;
00492   } while (0);
00493 
00494   return False;
00495 }


Generated on Tue Mar 25 14:35:42 2014 for live by  doxygen 1.5.2