ATLAS Offline Software
Loading...
Searching...
No Matches
IdentifiedSharedQueue.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <boost/interprocess/ipc/message_queue.hpp>
8
9#include <sstream>
10
11using namespace boost::interprocess;
12
13
14//const std::size_t MAX_MSG_SIZE = 4096;
15
16namespace AthenaInterprocess {
17
18//- construction/destruction -------------------------------------------------
23
24 IdentifiedSharedQueue::IdentifiedSharedQueue( const std::string& name, int max_msg, std::size_t max_size, bool do_unlink ) :
25 SharedQueue( name, max_msg, max_size, do_unlink )
26{
27/* empty */
28}
29
30//- public member functions --------------------------------------------------
31inline std::string add_pid( const std::string& buf )
32{
33 std::ostringstream s;
34 s << (long)getpid() << '\0' << buf;
35 return s.str();
36}
37
38bool IdentifiedSharedQueue::try_send( const std::string& buf )
39{
40 return this->SharedQueue::try_send( add_pid( buf ) );
41}
42
43bool IdentifiedSharedQueue::send( const std::string& buf )
44{
45 return this->SharedQueue::send( add_pid( buf ) );
46}
47
48inline std::string get_pid( const std::string& buf, pid_t &pid )
49{
50 std::istringstream s( buf );
51 long id = -1;
52 s >> id;
53 pid = (pid_t)id;
54 std::string::size_type pos = s.tellg();
55 if ( (pos+1) <= buf.size() )
56 return buf.substr( pos+1 );
57 return "";
58}
59
60
62{
63 pid_t pid;
64 return try_receive( pid );
65}
66
68{
69 const std::string& buf = this->SharedQueue::try_receive();
70 return get_pid( buf, id );
71}
72
74{
75 pid_t pid;
76 return receive( pid );
77}
78
80{
81 const std::string& buf = this->SharedQueue::receive();
82 return get_pid( buf, id );
83}
84
85} // namespace AthenaInterprocess
int32_t pid_t
virtual bool try_send(const std::string &)
virtual std::string try_receive()
virtual bool try_send(const std::string &)
virtual std::string receive()
virtual bool send(const std::string &)
std::string add_pid(const std::string &buf)
std::string get_pid(const std::string &buf, pid_t &pid)