Commit 32b41a8d authored by Dorian Guillois's avatar Dorian Guillois
Browse files

Merge branch 'master' of http://git.centreon.com/centreon-connector into icmp_v2

parents ee809bfe 8925a181
......@@ -28,8 +28,7 @@
# include "com/centreon/connector/ssh/orders/parser.hh"
# include "com/centreon/connector/ssh/reporter.hh"
# include "com/centreon/connector/ssh/sessions/credentials.hh"
# include "com/centreon/io/standard_input.hh"
# include "com/centreon/io/standard_output.hh"
# include "com/centreon/io/file_stream.hh"
CCCS_BEGIN()
......@@ -77,8 +76,8 @@ private:
reporter _reporter;
std::map<sessions::credentials, sessions::session*>
_sessions;
io::standard_input _sin;
io::standard_output _sout;
io::file_stream _sin;
io::file_stream _sout;
};
CCCS_END()
......
/*
** Copyright 2011 Merethis
** Copyright 2011-2012 Merethis
**
** This file is part of Centreon Connector SSH.
**
......@@ -35,16 +35,20 @@ namespace sessions {
*/
class socket_handle : public com::centreon::handle {
public:
socket_handle(native_handle internal_handle = -1);
socket_handle(
native_handle handl = native_handle_null);
~socket_handle() throw ();
void close();
native_handle get_native_handle();
unsigned long read(void* data, unsigned long size);
void set_native_handle(native_handle internal_handle);
void set_native_handle(native_handle handl);
unsigned long write(void const* data, unsigned long size);
private:
socket_handle(socket_handle const& sh);
socket_handle& operator=(socket_handle const& sh);
native_handle _handl;
};
}
......
......@@ -44,7 +44,8 @@ check::check()
_cmd_id(0),
_listnr(NULL),
_session(NULL),
_step(chan_open) {}
_step(chan_open),
_timeout(0) {}
/**
* Destructor.
......
......@@ -20,7 +20,10 @@
#include <assert.h>
#include <memory>
#include <stdio.h>
#include <stdlib.h>
#include "com/centreon/concurrency/locker.hh"
#include "com/centreon/concurrency/mutex.hh"
#include "com/centreon/connector/ssh/checks/check.hh"
#include "com/centreon/connector/ssh/checks/result.hh"
#include "com/centreon/connector/ssh/multiplexer.hh"
......@@ -43,7 +46,7 @@ extern volatile bool should_exit;
/**
* Default constructor.
*/
policy::policy() {
policy::policy() : _sin(stdin), _sout(stdout) {
// Send information back.
multiplexer::instance().handle_manager::add(&_sout, &_reporter);
......@@ -190,6 +193,11 @@ void policy::on_quit() {
* @param[in] r Check result.
*/
void policy::on_result(checks::result const& r) {
static concurrency::mutex processing_mutex;
// Lock mutex.
concurrency::locker lock(&processing_mutex);
// Remove check from list.
std::map<unsigned long long, std::pair<checks::check*, sessions::session*> >::iterator chk;
chk = _checks.find(r.get_command_id());
......@@ -244,6 +252,7 @@ void policy::on_result(checks::result const& r) {
}
}
}
lock.unlock();
// Send check result back to monitoring engine.
_reporter.send_result(r);
......
......@@ -219,7 +219,7 @@ void session::connect() {
_socket.set_native_handle(mysocket);
// Register with multiplexer.
multiplexer::instance().handle_manager::add(&_socket, this);
multiplexer::instance().handle_manager::add(&_socket, this, true);
// Launch the connection process.
logging::debug(logging::medium)
......@@ -525,7 +525,7 @@ void session::_startup() {
// Exchange banners, keys, setup crypto, compression, ...
int retval(libssh2_session_startup(
_session,
_socket.get_internal_handle()));
_socket.get_native_handle()));
if (retval) {
if (retval != LIBSSH2_ERROR_EAGAIN) { // Fatal failure.
char* msg;
......
/*
** Copyright 2011 Merethis
** Copyright 2011-2012 Merethis
**
** This file is part of Centreon Connector SSH.
**
......@@ -38,10 +38,9 @@ using namespace com::centreon::connector::ssh::sessions;
/**
* Default constructor.
*
* @param[in] internal_handle Native socket descriptor.
* @param[in] handl Native socket descriptor.
*/
socket_handle::socket_handle(native_handle internal_handle)
: handle(internal_handle) {}
socket_handle::socket_handle(native_handle handl) : _handl(handl) {}
/**
* Destructor.
......@@ -54,14 +53,23 @@ socket_handle::~socket_handle() throw () {
* Close socket descriptor.
*/
void socket_handle::close() {
if (_internal_handle >= 0) {
shutdown(_internal_handle, SHUT_RDWR);
::close(_internal_handle);
_internal_handle = -1;
if (_handl != native_handle_null) {
shutdown(_handl, SHUT_RDWR);
::close(_handl);
_handl = native_handle_null;
}
return ;
}
/**
* Get the native socket handle.
*
* @return Native socket handle.
*/
native_handle socket_handle::get_native_handle() {
return (_handl);
}
/**
* Read from socket descriptor.
*
......@@ -71,7 +79,7 @@ void socket_handle::close() {
* @return Number of bytes actually read.
*/
unsigned long socket_handle::read(void* data, unsigned long size) {
ssize_t rb(::read(_internal_handle, data, size));
ssize_t rb(::read(_handl, data, size));
if (rb < 0) {
char const* msg(strerror(errno));
throw (basic_error() << "socket read error: " << msg);
......@@ -82,11 +90,11 @@ unsigned long socket_handle::read(void* data, unsigned long size) {
/**
* Set socket descriptor.
*
* @param[in] internal_handle Native socket descriptor.
* @param[in] handl Native socket descriptor.
*/
void socket_handle::set_native_handle(native_handle internal_handle) {
void socket_handle::set_native_handle(native_handle handl) {
this->close();
_internal_handle = internal_handle;
_handl = handl;
return ;
}
......@@ -101,7 +109,7 @@ void socket_handle::set_native_handle(native_handle internal_handle) {
unsigned long socket_handle::write(
void const* data,
unsigned long size) {
ssize_t wb(::write(_internal_handle, data, size));
ssize_t wb(::write(_handl, data, size));
if (wb < 0) {
char const* msg(strerror(errno));
throw (basic_error() << "socket write error: " << msg);
......
/*
** Copyright 2011 Merethis
** Copyright 2011-2012 Merethis
**
** This file is part of Centreon Connector SSH.
**
......@@ -74,6 +74,15 @@ bool buffer_handle::empty() const {
return (_buffer.empty());
}
/**
* Get the native handle.
*
* @return Invalid handle.
*/
native_handle buffer_handle::get_native_handle() {
return (native_handle_null);
}
/**
* Read data.
*
......
/*
** Copyright 2011 Merethis
** Copyright 2011-2012 Merethis
**
** This file is part of Centreon Connector SSH.
**
......@@ -38,6 +38,8 @@ public:
buffer_handle& operator=(buffer_handle const& bh);
void close();
bool empty() const;
com::centreon::native_handle
get_native_handle();
unsigned long read(void* data, unsigned long size);
unsigned long write(void const* data, unsigned long size);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment