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 531 of file Groupsock.cpp.

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

Referenced by GroupsockLookupTable::Lookup().

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

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

Definition at line 465 of file Groupsock.cpp.

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

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

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

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

Definition at line 446 of file Groupsock.cpp.

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

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

Definition at line 499 of file Groupsock.cpp.

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

Referenced by GroupsockLookupTable::AddNew().

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

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

Definition at line 473 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().

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


Generated on Mon Apr 29 13:28:08 2013 for live by  doxygen 1.5.2