]> git.proxmox.com Git - ceph.git/blob - ceph/src/msg/simple/PipeConnection.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / msg / simple / PipeConnection.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #include "msg/Message.h"
16 #include "Pipe.h"
17 #include "SimpleMessenger.h"
18 #include "PipeConnection.h"
19
20 PipeConnection::~PipeConnection()
21 {
22 if (pipe) {
23 pipe->put();
24 pipe = NULL;
25 }
26 }
27
28 Pipe* PipeConnection::get_pipe()
29 {
30 Mutex::Locker l(lock);
31 if (pipe)
32 return pipe->get();
33 return NULL;
34 }
35
36 bool PipeConnection::try_get_pipe(Pipe **p)
37 {
38 Mutex::Locker l(lock);
39 if (failed) {
40 *p = NULL;
41 } else {
42 if (pipe)
43 *p = pipe->get();
44 else
45 *p = NULL;
46 }
47 return !failed;
48 }
49
50 bool PipeConnection::clear_pipe(Pipe *old_p)
51 {
52 Mutex::Locker l(lock);
53 if (old_p == pipe) {
54 pipe->put();
55 pipe = NULL;
56 failed = true;
57 return true;
58 }
59 return false;
60 }
61
62 void PipeConnection::reset_pipe(Pipe *p)
63 {
64 Mutex::Locker l(lock);
65 if (pipe)
66 pipe->put();
67 pipe = p->get();
68 }
69
70 bool PipeConnection::is_connected()
71 {
72 return static_cast<SimpleMessenger*>(msgr)->is_connected(this);
73 }
74
75 int PipeConnection::send_message(Message *m)
76 {
77 assert(msgr);
78 return static_cast<SimpleMessenger*>(msgr)->send_message(m, this);
79 }
80
81 void PipeConnection::send_keepalive()
82 {
83 static_cast<SimpleMessenger*>(msgr)->send_keepalive(this);
84 }
85
86 void PipeConnection::mark_down()
87 {
88 if (msgr)
89 static_cast<SimpleMessenger*>(msgr)->mark_down(this);
90 }
91
92 void PipeConnection::mark_disposable()
93 {
94 if (msgr)
95 static_cast<SimpleMessenger*>(msgr)->mark_disposable(this);
96 }