source: ThirdParty/JobMarket/src/JobMarket/Operations/SyncOperation.cpp@ a5c293

AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator Enhanced_StructuralOptimization_continued Exclude_Hydrogens_annealWithBondGraph ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity JobMarket_RobustOnKillsSegFaults PythonUI_with_named_parameters StoppableMakroAction TremoloParser_IncreasedPrecision
Last change on this file since a5c293 was a5c293, checked in by Frederik Heber <frederik.heber@…>, 7 years ago

FIX: SyncOperation now checks error codes from connect and close.

  • FragmentController checks the derived SyncOperations' status in order to set the exit flag. Now, if we cannot connect to the server, then the controller will have a non-zero exit flag.
  • Note that the exitflag was set already for all AsyncOperations.
  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 * Project: JobMarket
3 * Description: asynchronous Server/Controller/Client-approach to parallel computing, based on boost::asio
4 * Copyright (C) 2010 Frederik Heber. All rights reserved.
5 *
6 */
7
8/*
9 * SyncOperation.cpp
10 *
11 * Created on: Mar 04, 2012
12 * Author: heber
13 */
14
15
16// include config.h
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
20
21// boost asio needs specific operator new
22#include <boost/asio.hpp>
23
24//#include "CodePatterns/MemDebug.hpp"
25
26#include "JobMarket/Operations/SyncOperation.hpp"
27
28#include <boost/bind.hpp>
29#include <vector>
30#include "JobMarket/Connection.hpp" // Must come before boost/serialization headers.
31#include "CodePatterns/Info.hpp"
32#include "CodePatterns/Log.hpp"
33
34/** Internal function to connect connection_.
35 *
36 */
37void SyncOperation::connect(const std::string& _host, const std::string& _service)
38{
39 // Resolve the host name into an IP address.
40 boost::asio::ip::tcp::resolver resolver(connection_.socket().get_io_service());
41 boost::asio::ip::tcp::resolver::query query(_host, _service);
42 boost::asio::ip::tcp::resolver::iterator endpoint_iterator =
43 resolver.resolve(query);
44 // check whether host could be resolved
45 if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {
46 boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
47
48 // Start an asynchronous connect operation.
49 LOG(3, "DEBUG: Connecting synchronously to endpoint " << endpoint << " ...");
50 boost::system::error_code ec;
51 connection_.socket().connect(endpoint, ec);
52 if (ec) {
53 ELOG(1, ec.message());
54 status = Operation::error;
55 }
56 } else {
57 status = Operation::error;
58 }
59}
60
61
62/** Internal function to disconnect connection_ correctly.
63 *
64 */
65void SyncOperation::disconnect()
66{
67 boost::system::error_code ec;
68 connection_.socket().close(ec);
69 if (ec) {
70 ELOG(1, ec.message());
71 status = Operation::error;
72 }
73}
74
75/** Wrapper function for the virtual call to internal() that connects and disconnects.
76 *
77 * @param _host host address to connect to
78 * @param _service service to connect to
79 */
80void SyncOperation::operator()(const std::string& _host, const std::string& _service)
81{
82 DEBUG_FUNCTION_ENTRYEXIT
83
84 status = Operation::running;
85
86 // connect
87 connect(_host, _service);
88
89 // call virtual function to continue
90 if (status == Operation::running)
91 internal();
92
93 // disconnect
94 if (status == Operation::running)
95 disconnect();
96
97 if (status == Operation::running)
98 status = Operation::success;
99}
Note: See TracBrowser for help on using the repository browser.