root/plugin/ipc/connectionidentifier.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /****************************************************************************
   2  *   Copyright (C) 2006-2008 by Jason Ansel, Kapil Arya, and Gene Cooperman *
   3  *   jansel@csail.mit.edu, kapil@ccs.neu.edu, gene@ccs.neu.edu              *
   4  *                                                                          *
   5  *   This file is part of the dmtcp/src module of DMTCP (DMTCP:dmtcp/src).  *
   6  *                                                                          *
   7  *  DMTCP:dmtcp/src is free software: you can redistribute it and/or        *
   8  *  modify it under the terms of the GNU Lesser General Public License as   *
   9  *  published by the Free Software Foundation, either version 3 of the      *
  10  *  License, or (at your option) any later version.                         *
  11  *                                                                          *
  12  *  DMTCP:dmtcp/src is distributed in the hope that it will be useful,      *
  13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
  14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
  15  *  GNU Lesser General Public License for more details.                     *
  16  *                                                                          *
  17  *  You should have received a copy of the GNU Lesser General Public        *
  18  *  License along with DMTCP:dmtcp/src.  If not, see                        *
  19  *  <http://www.gnu.org/licenses/>.                                         *
  20  ****************************************************************************/
  21 
  22 #pragma once
  23 #ifndef CONNECTIONIDENTIFIER_H
  24 #define CONNECTIONIDENTIFIER_H
  25 
  26 #include <stdint.h>
  27 #include "dmtcpalloc.h"
  28 #include "dmtcp.h"
  29 #include "jalloc.h"
  30 #include "jserialize.h"
  31 #include "ipc.h"
  32 
  33 namespace dmtcp
  34 {
  35   class ConnectionIdentifier
  36   {
  37     public:
  38 #ifdef JALIB_ALLOCATOR
  39       static void* operator new(size_t nbytes, void* p) { return p; }
  40       static void* operator new(size_t nbytes) { JALLOC_HELPER_NEW(nbytes); }
  41       static void  operator delete(void* p) { JALLOC_HELPER_DELETE(p); }
  42 #endif
  43       static ConnectionIdentifier create();
  44       static ConnectionIdentifier null();
  45       static ConnectionIdentifier self();
  46 
  47       static void serialize ( jalib::JBinarySerializer& o );
  48 
  49       uint64_t   hostid() const { return _upid._hostid; }
  50       pid_t  pid() const { return _upid._pid; }
  51       uint64_t time() const { return _upid._time; }
  52       int64_t   conId() const { return _id; }
  53       //int conId() const;
  54       //const UniquePid& pid() const;
  55 
  56       ConnectionIdentifier (int id = -1);
  57       ConnectionIdentifier(DmtcpUniqueProcessId id) {
  58         _upid = id;
  59         _id = -1;
  60       }
  61 
  62       bool isNull() const { return _id < 0; }
  63 
  64       bool operator==(const ConnectionIdentifier& that) const;
  65       bool operator< (const ConnectionIdentifier& that) const;
  66       bool operator!=(const ConnectionIdentifier& that) const
  67       { return !(*this == that); }
  68 
  69     private:
  70       DmtcpUniqueProcessId _upid;
  71       int64_t   _id;
  72   };
  73 
  74   class ConnMsg {
  75     public:
  76     enum MsgType {
  77       INVALID = -1,
  78       HANDSHAKE = 0,
  79       DRAIN,
  80       REFILL
  81     };
  82 
  83     ConnMsg(enum MsgType t = INVALID) {
  84       strcpy(sign, HANDSHAKE_SIGNATURE_MSG);
  85       type = t;
  86       size = sizeof(ConnMsg);
  87       extraBytes = 0;
  88     }
  89 
  90     void poison() {
  91       sign[0] = '\0';
  92       type = INVALID;
  93     }
  94 
  95     void assertValid(enum MsgType t) {
  96       JASSERT(strcmp(sign, HANDSHAKE_SIGNATURE_MSG) == 0) (sign)
  97         .Text("read invalid message, signature mismatch. (External socket?)");
  98       JASSERT(size == sizeof(ConnMsg)) (size) (sizeof(ConnMsg))
  99         .Text("read invalid message, size mismatch.");
 100       JASSERT(type == t) ((int)t) ((int)type) .Text("Wrong Msg Type.");
 101     }
 102 
 103     ConnectionIdentifier from;
 104     ConnectionIdentifier coordId;
 105 
 106     char sign[32];
 107     int32_t type;
 108     int32_t size;
 109     int32_t extraBytes;
 110     char    padding[4];
 111   };
 112 
 113   ostream& operator<<(ostream& o, const ConnectionIdentifier& id);
 114 }
 115 
 116 #endif

/* [<][>][^][v][top][bottom][index][help] */