~ubuntu-branches/ubuntu/precise/zeromq/precise

« back to all changes in this revision

Viewing changes to src/owned.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Lucina
  • Date: 2011-05-13 12:43:09 UTC
  • mfrom: (7.2.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110513124309-m3gdt964ga67rcwu
Tags: 2.1.7-1
* New upstream version. (closes: #619374)
* --with-system-pgm is now used instead of the embedded OpenPGM library. 
* Added Debian watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Copyright (c) 2007-2010 iMatix Corporation
3
 
 
4
 
    This file is part of 0MQ.
5
 
 
6
 
    0MQ is free software; you can redistribute it and/or modify it under
7
 
    the terms of the Lesser GNU General Public License as published by
8
 
    the Free Software Foundation; either version 3 of the License, or
9
 
    (at your option) any later version.
10
 
 
11
 
    0MQ is distributed in the hope that it will be useful,
12
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
    Lesser GNU General Public License for more details.
15
 
 
16
 
    You should have received a copy of the Lesser GNU General Public License
17
 
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
*/
19
 
 
20
 
#include "owned.hpp"
21
 
#include "err.hpp"
22
 
 
23
 
zmq::owned_t::owned_t (object_t *parent_, socket_base_t *owner_) :
24
 
    object_t (parent_),
25
 
    owner (owner_),
26
 
    sent_seqnum (0),
27
 
    processed_seqnum (0),
28
 
    shutting_down (false)
29
 
{
30
 
}
31
 
 
32
 
zmq::owned_t::~owned_t ()
33
 
{
34
 
}
35
 
 
36
 
void zmq::owned_t::inc_seqnum ()
37
 
{
38
 
    //  NB: This function may be called from a different thread!
39
 
    sent_seqnum.add (1);
40
 
}
41
 
 
42
 
void zmq::owned_t::term ()
43
 
{
44
 
    send_term_req (owner, this);
45
 
}
46
 
 
47
 
void zmq::owned_t::process_term ()
48
 
{
49
 
    zmq_assert (!shutting_down);
50
 
    shutting_down = true;
51
 
    finalise ();
52
 
}
53
 
 
54
 
void zmq::owned_t::process_seqnum ()
55
 
{
56
 
    //  Catch up with counter of processed commands.
57
 
    processed_seqnum++;
58
 
    finalise ();
59
 
}
60
 
 
61
 
void zmq::owned_t::finalise ()
62
 
{
63
 
    //  If termination request was already received and there are no more
64
 
    //  commands to wait for, terminate the object.
65
 
    if (shutting_down && processed_seqnum == sent_seqnum.get ()) {
66
 
        process_unplug ();
67
 
        send_term_ack (owner);
68
 
        delete this;
69
 
    }
70
 
}
71