|
1 | 1 | //! This crate provides high level SCTP networking.
|
2 | 2 | //! Currently it only supports basic SCTP features like multi-homing
|
3 | 3 | //! in one-to-one and one-to-many associations.
|
4 |
| -//! SCTP notifications and working directly on association is not supported yet |
| 4 | +//! SCTP notifications and working directly on associations is not supported yet |
5 | 5 | //! but is in the TODO list.
|
6 | 6 |
|
7 | 7 | extern crate sctp_sys;
|
@@ -129,7 +129,7 @@ impl SctpStream {
|
129 | 129 |
|
130 | 130 | /// Set `timeout` in seconds for operation `dir` (either receive or send)
|
131 | 131 | pub fn set_timeout(&self, dir: SoDirection, timeout: i32) -> Result<()> {
|
132 |
| - // Workaround: Use onf long instead of time_t which does not compile in windows x86_64 |
| 132 | + // Workaround: Use of long instead of libc::time_t which does not compile in windows x86_64 |
133 | 133 | let tval = libc::timeval { tv_sec: timeout as libc::c_long, tv_usec: 0 };
|
134 | 134 | return self.0.setsockopt(libc::SOL_SOCKET, dir.timeout_opt(), &tval);
|
135 | 135 | }
|
@@ -229,11 +229,47 @@ impl SctpEndpoint {
|
229 | 229 | return self.0.sendmsg(msg, Some(address), stream, 0);
|
230 | 230 | }
|
231 | 231 |
|
232 |
| - /// Get local socket addresses on which this socket is bound |
| 232 | + /// Get local socket addresses to which this socket is bound |
233 | 233 | pub fn local_addrs(&self) -> Result<Vec<SocketAddr>> {
|
234 | 234 | return self.0.local_addrs(0);
|
235 | 235 | }
|
236 | 236 |
|
| 237 | + /// Shuts down the read, write, or both halves of this connection |
| 238 | + pub fn shutdown(&self, how: Shutdown) -> Result<()> { |
| 239 | + return self.0.shutdown(how); |
| 240 | + } |
| 241 | + |
| 242 | + /// Set or unset SCTP_NODELAY option |
| 243 | + pub fn set_nodelay(&self, nodelay: bool) -> Result<()> { |
| 244 | + let val: libc::c_int = if nodelay { 1 } else { 0 }; |
| 245 | + return self.0.setsockopt(SOL_SCTP, sctp_sys::SCTP_NODELAY, &val); |
| 246 | + } |
| 247 | + |
| 248 | + /// Verify if SCTP_NODELAY option is activated for this socket |
| 249 | + pub fn has_nodelay(&self) -> Result<bool> { |
| 250 | + let val: libc::c_int = try!(self.0.sctp_opt_info(sctp_sys::SCTP_NODELAY, 0)); |
| 251 | + return Ok(val == 1); |
| 252 | + } |
| 253 | + |
| 254 | + /// Set the socket buffer size for the direction specified by `dir`. |
| 255 | + /// Linux systems will double the provided size |
| 256 | + pub fn set_buffer_size(&self, dir: SoDirection, size: usize) -> Result<()> { |
| 257 | + return self.0.setsockopt(libc::SOL_SOCKET, dir.buffer_opt(), &(size as libc::c_int)); |
| 258 | + } |
| 259 | + |
| 260 | + /// Get the socket buffer size for the direction specified by `dir` |
| 261 | + pub fn get_buffer_size(&self, dir: SoDirection) -> Result<(usize)> { |
| 262 | + let val: u32 = try!(self.0.getsockopt(libc::SOL_SOCKET, dir.buffer_opt())); |
| 263 | + return Ok(val as usize); |
| 264 | + } |
| 265 | + |
| 266 | + /// Set `timeout` in seconds for operation `dir` (either receive or send) |
| 267 | + pub fn set_timeout(&self, dir: SoDirection, timeout: i32) -> Result<()> { |
| 268 | + // Workaround: Use of long instead of libc::time_t which does not compile in windows x86_64 |
| 269 | + let tval = libc::timeval { tv_sec: timeout as libc::c_long, tv_usec: 0 }; |
| 270 | + return self.0.setsockopt(libc::SOL_SOCKET, dir.timeout_opt(), &tval); |
| 271 | + } |
| 272 | + |
237 | 273 | /// Try to clone this socket
|
238 | 274 | pub fn try_clone(&self) -> Result<SctpEndpoint> {
|
239 | 275 | return Ok(SctpEndpoint(try!(self.0.try_clone())));
|
@@ -321,16 +357,23 @@ impl SctpListener {
|
321 | 357 | return Ok((SctpStream(sock), addr));
|
322 | 358 | }
|
323 | 359 |
|
324 |
| - /// Iterate over new connections. |
| 360 | + /// Iterate over new connections |
325 | 361 | pub fn incoming(&self) -> Incoming {
|
326 | 362 | return Incoming(self);
|
327 | 363 | }
|
328 | 364 |
|
329 |
| - /// Get the listener ocal addresses |
| 365 | + /// Get the listener local addresses |
330 | 366 | pub fn local_addrs(&self) -> Result<Vec<SocketAddr>> {
|
331 | 367 | return self.0.local_addrs(0);
|
332 | 368 | }
|
333 | 369 |
|
| 370 | + /// Set `timeout` in seconds on accept |
| 371 | + pub fn set_timeout(&self, timeout: i32) -> Result<()> { |
| 372 | + // Workaround: Use of long instead of libc::time_t which does not compile in windows x86_64 |
| 373 | + let tval = libc::timeval { tv_sec: timeout as libc::c_long, tv_usec: 0 }; |
| 374 | + return self.0.setsockopt(libc::SOL_SOCKET, libc::SO_RCVTIMEO, &tval); |
| 375 | + } |
| 376 | + |
334 | 377 | /// Try to clone this listener
|
335 | 378 | pub fn try_clone(&self) -> Result<SctpListener> {
|
336 | 379 | return Ok(SctpListener(try!(self.0.try_clone())));
|
|
0 commit comments