17 #ifndef __DEVICE_NETWORK_H__
18 #define __DEVICE_NETWORK_H__
22 # include <boost/archive/binary_iarchive.hpp>
23 # include <boost/archive/binary_oarchive.hpp>
24 # include <boost/archive/text_iarchive.hpp>
25 # include <boost/archive/text_oarchive.hpp>
26 # include <boost/array.hpp>
27 # include <boost/asio.hpp>
28 # include <boost/bind.hpp>
29 # include <boost/serialization/vector.hpp>
30 # include <boost/thread.hpp>
52 using boost::asio::ip::tcp;
54 static const int SERVER_PORT = 5120;
55 static const int DISCOVER_PORT = 5121;
56 static const string DISCOVER_REQUEST_MSG =
"REQUEST_RENDER_SERVER_IP";
57 static const string DISCOVER_REPLY_MSG =
"REPLY_RENDER_SERVER_IP";
60 typedef boost::archive::text_oarchive o_archive;
61 typedef boost::archive::text_iarchive i_archive;
63 typedef boost::archive::binary_oarchive o_archive;
64 typedef boost::archive::binary_iarchive i_archive;
75 ~network_device_memory()
96 void network_error(
const string &message)
104 return true ? error_count > 0 :
false;
116 RPCSend(tcp::socket &socket_, NetworkError *
e,
const string &name_ =
"")
117 : name(name_), socket(socket_), archive(archive_stream), sent(false)
121 fprintf(stderr,
"rpc send %s\n", name.c_str());
132 archive &mem.
type &string(mem.
name);
133 archive &mem.interpolation &mem.extension;
137 template<
typename T>
void add(
const T &
data)
148 archive &
task.shader_input &
task.shader_output &
task.shader_eval_type;
149 archive &
task.shader_x &
task.shader_w;
150 archive &
task.need_finish_queue;
155 archive &tile.
x &tile.
y &tile.
w &tile.
h;
163 boost::system::error_code
error;
166 string archive_str = archive_stream.str();
169 ostringstream header_stream;
170 header_stream << setw(8) <<
hex << archive_str.size();
171 string header_str = header_stream.str();
177 error_func->network_error(
error.message());
184 error_func->network_error(
error.message());
191 boost::system::error_code
error;
197 error_func->network_error(
error.message());
203 ostringstream archive_stream;
206 NetworkError *error_func;
213 RPCReceive(tcp::socket &socket_, NetworkError *
e)
214 : socket(socket_), archive_stream(
NULL), archive(
NULL)
219 boost::system::error_code
error;
223 error_func->network_error(
error.message());
227 if (
len == header.size()) {
229 string header_str(&header[0], header.size());
230 istringstream header_stream(header_str);
234 if ((header_stream >>
hex >> data_size)) {
240 error_func->network_error(
error.message());
242 if (
len == data_size) {
243 archive_str = (
data.size()) ?
string(&
data[0],
data.size()) :
string(
"");
245 archive_stream =
new istringstream(archive_str);
246 archive =
new i_archive(*archive_stream);
249 fprintf(stderr,
"rpc receive %s\n", name.c_str());
252 error_func->network_error(
"Network receive error: data size doesn't match header");
256 error_func->network_error(
"Network receive error: can't decode data size from header");
260 error_func->network_error(
"Network receive error: invalid header size");
267 delete archive_stream;
270 void read(network_device_memory &mem,
string &name)
272 *archive &mem.data_type &mem.data_elements &mem.data_size;
273 *archive &mem.data_width &mem.data_height &mem.data_depth &mem.device_pointer;
274 *archive &mem.type &name;
275 *archive &mem.interpolation &mem.extension;
276 *archive &mem.device_pointer;
278 mem.name = name.c_str();
279 mem.host_pointer = 0;
287 template<
typename T>
void read(
T &
data)
294 boost::system::error_code
error;
298 error_func->network_error(
error.message());
302 cout <<
"Network receive error: buffer size doesn't match expected size\n";
312 *archive &
task.shader_input &
task.shader_output &
task.shader_eval_type;
313 *archive &
task.shader_x &
task.shader_w;
314 *archive &
task.need_finish_queue;
321 *archive &tile.
x &tile.
y &tile.
w &tile.
h;
334 istringstream *archive_stream;
336 NetworkError *error_func;
341 class ServerDiscovery {
343 explicit ServerDiscovery(
bool discover =
false)
344 : listen_socket(io_service), collect_servers(false)
348 listen_endpoint.port(DISCOVER_PORT);
350 listen_socket.open(listen_endpoint.protocol());
352 boost::asio::socket_base::reuse_address option(
true);
353 listen_socket.set_option(option);
355 listen_socket.bind(listen_endpoint);
362 collect_servers =
true;
365 broadcast_message(DISCOVER_REQUEST_MSG);
369 work =
new boost::asio::io_service::work(io_service);
370 thread =
new boost::thread(boost::bind(&boost::asio::io_service::run, &io_service));
393 void handle_receive_from(
const boost::system::error_code &
error,
size_t size)
396 cout <<
"Server discovery receive error: " <<
error.message() <<
"\n";
401 string msg = string(receive_buffer,
size);
404 if (collect_servers) {
405 if (msg == DISCOVER_REPLY_MSG) {
406 string address = receive_endpoint.address().to_string();
411 bool found = std::find(servers.begin(), servers.end(), address) != servers.end();
414 servers.push_back(address);
421 if (msg == DISCOVER_REQUEST_MSG)
422 broadcast_message(DISCOVER_REPLY_MSG);
433 boost::bind(&ServerDiscovery::handle_receive_from,
436 boost::asio::placeholders::bytes_transferred));
439 void broadcast_message(
const string &msg)
442 boost::asio::ip::udp::socket socket(io_service);
444 socket.open(boost::asio::ip::udp::v4());
447 socket.set_option(option);
449 boost::asio::ip::udp::endpoint broadcast_endpoint(
450 boost::asio::ip::address::from_string(
"255.255.255.255"), DISCOVER_PORT);
457 boost::asio::io_service io_service;
458 boost::asio::ip::udp::endpoint listen_endpoint;
459 boost::asio::ip::udp::socket listen_socket;
463 boost::asio::io_service::work *work;
467 char receive_buffer[256];
468 boost::asio::ip::udp::endpoint receive_endpoint;
472 string cycles_version;
482 bool collect_servers;
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
device_ptr device_pointer
#define CCL_NAMESPACE_END
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
static void error(const char *str)
static void add(GHash *messages, MemArena *memarena, const Message *msg)
struct blender::compositor::@172::@174 task
static const char hex[17]
__forceinline bool any(const avxb &b)
__forceinline const avxi broadcast(const int *ptr)