groupsock/Groupsock.cpp File Reference

#include "Groupsock.hh"
#include "GroupsockHelper.hh"
#include "TunnelEncaps.hh"
#include <strstream.h>
#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 HashTablegetSocketTable (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 538 of file Groupsock.cpp.

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

Referenced by GroupsockLookupTable::Lookup().

00538                                                                         {
00539   do {
00540     // Make sure the "sock" parameter is in bounds:
00541     if (sock < 0) break;
00542 
00543     HashTable* sockets = getSocketTable(env);
00544     if (sockets == NULL) break;
00545 
00546     return (Groupsock*)sockets->Lookup((char*)(long)sock);
00547   } while (0);
00548 
00549   return NULL;
00550 }

static HashTable* getSocketTable ( UsageEnvironment env  )  [static]

Definition at line 470 of file Groupsock.cpp.

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

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

00470                                                         {
00471   if (env.groupsockPriv == NULL) { // We need to create it
00472     env.groupsockPriv = HashTable::create(ONE_WORD_HASH_KEYS);
00473   }
00474   return (HashTable*)(env.groupsockPriv);
00475 }

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

Definition at line 451 of file Groupsock.cpp.

00451                                                                       {
00452   UsageEnvironment& s1 = s << timestampString() << " Groupsock("
00453                            << g.socketNum() << ": "
00454                            << our_inet_ntoa(g.groupAddress())
00455                            << ", " << g.port() << ", ";
00456   if (g.isSSM()) {
00457     return s1 << "SSM source: "
00458               <<  our_inet_ntoa(g.sourceFilterAddress()) << ")";
00459   } else {
00460     return s1 << (unsigned)(g.ttl()) << ")";
00461   }
00462 }

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

Definition at line 504 of file Groupsock.cpp.

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

Referenced by GroupsockLookupTable::AddNew().

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

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

Definition at line 477 of file Groupsock.cpp.

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

Referenced by GroupsockLookupTable::Remove().

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


Generated on Tue Oct 7 15:38:12 2008 for live by  doxygen 1.5.2