~registry/scalestack/trunk

« back to all changes in this revision

Viewing changes to scalestack/network/datagram.h

  • Committer: Eric Day
  • Date: 2010-12-04 17:17:34 UTC
  • mfrom: (56.1.9)
  • Revision ID: git-v1:9c392b034d652023a4b28ae2976aca128bb856c2
Merged Eric's branch with style updates, config file support, and other cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 */
44
44
class SCALESTACK_API datagram
45
45
{
46
 
  friend class datagram_provider;
47
 
 
48
46
public:
49
47
 
50
48
  datagram(datagram_service& datagram_service);
84
82
  void consume(size_t size);
85
83
 
86
84
  /**
87
 
   * Send data to the connection.  This is not buffered.  If data could
88
 
   * not be written, flush_send() will be called when it can be.
 
85
   * Send data to the connection. This is not buffered. If data could not
 
86
   * be written, flush_send() will be called when it can be.
89
87
   *
90
88
   * @param[in] buffer Buffer to write.
91
89
   * @param[in] size Size of buffer.
152
150
protected:
153
151
 
154
152
  kernel::module& _module;
155
 
  datagram_service& _service;
 
153
  datagram_service& _datagram_service;
156
154
 
157
155
private:
158
156
 
169
167
  datagram& operator=(const datagram&);
170
168
 
171
169
  datagram_provider* _datagram_provider;
 
170
 
 
171
  friend class datagram_provider;
172
172
};
173
173
 
174
174
/**
191
191
   * Set the datagram for this datagram_provider. This is used while
192
192
   * initializing the datagram handler.
193
193
   *
194
 
   * @param[in] bound_datagram Datagram to bind to this provider.
 
194
   * @param[in] datagram Datagram to bind to this provider.
195
195
   */
196
 
  void set_datagram(datagram* bound_datagram);
 
196
  void set_datagram(datagram* datagram);
197
197
 
198
198
  /**
199
199
   * Set the file descriptor to use for this connection.
210
210
  /**
211
211
   * Create the socket and bind to a specific local address.
212
212
   *
213
 
   * @param[in] address Address to bind to.
214
 
   * @param[in] address_size Size of the address structure.
 
213
   * @param[in] local Local address to bind to.
 
214
   * @param[in] local_size Size of the address structure.
215
215
   */
216
 
  void bind(const struct sockaddr& address, socklen_t address_size);
 
216
  void create(const struct sockaddr& local, socklen_t local_size);
217
217
 
218
218
  /**
219
 
   * Set the initial peer address for sending packets.
 
219
   * Set the initial peer address to send packets to.
220
220
   *
221
221
   * @param[in] peer Peer address to set.
222
222
   * @param[in] peer_size Size of peer address structure.
335
335
 
336
336
inline datagram::datagram(datagram_service& datagram_service):
337
337
  _module(datagram_service.get_module()),
338
 
  _service(datagram_service),
 
338
  _datagram_service(datagram_service),
339
339
  _datagram_provider(NULL)
340
340
{
341
341
}
403
403
  return _datagram;
404
404
}
405
405
 
406
 
inline void datagram_provider::set_datagram(datagram* bound_datagram)
 
406
inline void datagram_provider::set_datagram(datagram* datagram)
407
407
{
408
 
  _datagram = bound_datagram;
 
408
  _datagram = datagram;
409
409
  _datagram->_datagram_provider = this;
410
410
}
411
411
 
415
415
}
416
416
 
417
417
inline size_t datagram_provider::receive(uint8_t* buffer,
418
 
                                        size_t size,
419
 
                                        struct sockaddr& peer,
420
 
                                        socklen_t peer_size)
 
418
                                         size_t size,
 
419
                                         struct sockaddr& peer,
 
420
                                         socklen_t peer_size)
421
421
{
422
422
  return _datagram->receive(buffer, size, peer, peer_size);
423
423
}