GraphLab: Distributed Graph-Parallel API  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dc_receive.hpp
1 /**
2  * Copyright (c) 2009 Carnegie Mellon University.
3  * All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an "AS
13  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14  * express or implied. See the License for the specific language
15  * governing permissions and limitations under the License.
16  *
17  * For more about this software visit:
18  *
19  * http://www.graphlab.ml.cmu.edu
20  *
21  */
22 
23 
24 #ifndef DC_RECEIVE_HPP
25 #define DC_RECEIVE_HPP
26 #include <graphlab/rpc/dc_internal_types.hpp>
27 #include <graphlab/rpc/dc_types.hpp>
28 #include <graphlab/parallel/atomic.hpp>
29 namespace graphlab {
30 namespace dc_impl {
31 
32 /**
33 \ingroup rpc
34 \internal
35 Base class of the data receiving class.
36 This class forms the receiving side of a "multiplexer"
37 Data entering from a single socket will be passed to this
38 function through the incoming_data function call.
39 
40 This class must understand the packet header and issue the right
41 calls in the owning dc.
42 */
43 class dc_receive {
44  public:
45  dc_receive() { };
46  virtual ~dc_receive() { };
47 
48  /**
49  gets a buffer. The buffer length is returned in retbuflength
50  This will be used for receiving data.
51  If get_buffer() or advance_buffer() is called,
52  incoming_data will never be called.
53  */
54  virtual char* get_buffer(size_t& retbuflength) = 0;
55 
56  /**
57  Commits a buffer obtained using get_buffer.
58  c will be the result of a previous call to get_buffer() or advance_buffer()
59  This function should commit a range of bytes starting of c,
60  up to 'wrotelength' bytes. A new empty buffer should be returned
61  and the size is returned in retbuflength
62  */
63  virtual char* advance_buffer(char* c, size_t wrotelength,
64  size_t& retbuflength) = 0;
65 
66 
67  /**
68  * Last call sent to any instance of dc_receive.
69  * If the sender multithreads, the sending thread must shut down.
70  */
71  virtual void shutdown() = 0;
72 };
73 
74 
75 } // namespace dc_impl
76 } // namespace graphlab
77 #endif
78