@@ -45,20 +45,21 @@ pub struct MessageHandler {
45
45
/// careful to ensure you don't have races whereby you might register a new connection with an fd
46
46
/// the same as a yet-to-be-disconnect_event()-ed.
47
47
pub trait SocketDescriptor : cmp:: Eq + hash:: Hash + Clone {
48
- /// Attempts to send some data from the given Vec starting at the given offset to the peer.
48
+ /// Attempts to send some data from the given slice to the peer.
49
+ ///
49
50
/// Returns the amount of data which was sent, possibly 0 if the socket has since disconnected.
50
51
/// Note that in the disconnected case, a disconnect_event must still fire and further write
51
52
/// attempts may occur until that time.
52
53
///
53
- /// If the returned size is smaller than data.len() - write_offset , a write_available event must
54
+ /// If the returned size is smaller than data.len(), a write_available event must
54
55
/// trigger the next time more data can be written. Additionally, until the a send_data event
55
56
/// completes fully, no further read_events should trigger on the same peer!
56
57
///
57
58
/// If a read_event on this descriptor had previously returned true (indicating that read
58
59
/// events should be paused to prevent DoS in the send buffer), resume_read may be set
59
60
/// indicating that read events on this descriptor should resume. A resume_read of false does
60
61
/// *not* imply that further read events should be paused.
61
- fn send_data ( & mut self , data : & Vec < u8 > , write_offset : usize , resume_read : bool ) -> usize ;
62
+ fn send_data ( & mut self , data : & [ u8 ] , resume_read : bool ) -> usize ;
62
63
/// Disconnect the socket pointed to by this SocketDescriptor. Once this function returns, no
63
64
/// more calls to write_event, read_event or disconnect_event may be made with this descriptor.
64
65
/// No disconnect_event should be generated as a result of this call, though obviously races
@@ -387,7 +388,8 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
387
388
} ;
388
389
389
390
let should_be_reading = peer. pending_outbound_buffer . len ( ) < MSG_BUFF_SIZE ;
390
- let data_sent = descriptor. send_data ( next_buff, peer. pending_outbound_buffer_first_msg_offset , should_be_reading) ;
391
+ let pending = & next_buff[ peer. pending_outbound_buffer_first_msg_offset ..] ;
392
+ let data_sent = descriptor. send_data ( pending, should_be_reading) ;
391
393
peer. pending_outbound_buffer_first_msg_offset += data_sent;
392
394
if peer. pending_outbound_buffer_first_msg_offset == next_buff. len ( ) { true } else { false }
393
395
} {
@@ -1122,9 +1124,8 @@ mod tests {
1122
1124
}
1123
1125
1124
1126
impl SocketDescriptor for FileDescriptor {
1125
- fn send_data ( & mut self , data : & Vec < u8 > , write_offset : usize , _resume_read : bool ) -> usize {
1126
- assert ! ( write_offset < data. len( ) ) ;
1127
- data. len ( ) - write_offset
1127
+ fn send_data ( & mut self , data : & [ u8 ] , _resume_read : bool ) -> usize {
1128
+ data. len ( )
1128
1129
}
1129
1130
1130
1131
fn disconnect_socket ( & mut self ) { }
0 commit comments