]> git.proxmox.com Git - ceph.git/blame - ceph/src/msg/simple/PipeConnection.cc
update download target update for octopus release
[ceph.git] / ceph / src / msg / simple / PipeConnection.cc
CommitLineData
7c673cae
FG
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
20PipeConnection::~PipeConnection()
21{
22 if (pipe) {
23 pipe->put();
24 pipe = NULL;
25 }
26}
27
28Pipe* PipeConnection::get_pipe()
29{
30 Mutex::Locker l(lock);
31 if (pipe)
32 return pipe->get();
33 return NULL;
34}
35
36bool 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
50bool 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
62void PipeConnection::reset_pipe(Pipe *p)
63{
64 Mutex::Locker l(lock);
65 if (pipe)
66 pipe->put();
67 pipe = p->get();
68}
69
70bool PipeConnection::is_connected()
71{
72 return static_cast<SimpleMessenger*>(msgr)->is_connected(this);
73}
74
75int PipeConnection::send_message(Message *m)
76{
11fdf7f2 77 ceph_assert(msgr);
7c673cae
FG
78 return static_cast<SimpleMessenger*>(msgr)->send_message(m, this);
79}
80
81void PipeConnection::send_keepalive()
82{
83 static_cast<SimpleMessenger*>(msgr)->send_keepalive(this);
84}
85
86void PipeConnection::mark_down()
87{
88 if (msgr)
89 static_cast<SimpleMessenger*>(msgr)->mark_down(this);
90}
91
92void PipeConnection::mark_disposable()
93{
94 if (msgr)
95 static_cast<SimpleMessenger*>(msgr)->mark_disposable(this);
96}