1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * SendJobToWorkerOperation.cpp
|
---|
10 | *
|
---|
11 | * Created on: Feb 22, 2012
|
---|
12 | * Author: heber
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | // boost asio needs specific operator new
|
---|
21 | #include <boost/asio.hpp>
|
---|
22 |
|
---|
23 | #include "CodePatterns/MemDebug.hpp"
|
---|
24 |
|
---|
25 | #include "SendJobToWorkerOperation.hpp"
|
---|
26 |
|
---|
27 | #include <boost/bind.hpp>
|
---|
28 | #include <iostream>
|
---|
29 | #include "Connection.hpp" // Must come before boost/serialization headers.
|
---|
30 | #include "CodePatterns/Info.hpp"
|
---|
31 | #include "CodePatterns/Log.hpp"
|
---|
32 |
|
---|
33 | /** Handle connect operation to shutdown scheduler.
|
---|
34 | *
|
---|
35 | * \param e error code if something went wrong
|
---|
36 | * \param endpoint_iterator endpoint of the connection
|
---|
37 | */
|
---|
38 | void SendJobToWorkerOperation::handle_connect(const boost::system::error_code& e,
|
---|
39 | boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
|
---|
40 | {
|
---|
41 | Info info(__FUNCTION__);
|
---|
42 | if (!e)
|
---|
43 | {
|
---|
44 | // The connection::async_write() function will automatically
|
---|
45 | // serialize the data structure for us.
|
---|
46 | LOG(1, "INFO: Sending job #" << job->getId() << ".");
|
---|
47 | connection_.async_write(job,
|
---|
48 | boost::bind(&SendJobToWorkerOperation::handle_FinishOperation, this,
|
---|
49 | boost::asio::placeholders::error));
|
---|
50 | } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {
|
---|
51 | // Try the next endpoint.
|
---|
52 | connection_.socket().close();
|
---|
53 | boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
|
---|
54 | connection_.socket().async_connect(endpoint,
|
---|
55 | boost::bind(&SendJobToWorkerOperation::handle_connect, this,
|
---|
56 | boost::asio::placeholders::error, ++endpoint_iterator));
|
---|
57 | } else {
|
---|
58 | // An error occurred. Log it and return. Since we are not starting a new
|
---|
59 | // operation the io_service will run out of work to do and the client will
|
---|
60 | // exit.
|
---|
61 | Exitflag = ErrorFlag;
|
---|
62 | ELOG(1, e.message());
|
---|
63 | }
|
---|
64 | }
|
---|