Added set_keepalive to Connection and the ability to reconnect to a
server.
This commit is contained in:
parent
70031aa8d8
commit
3173accaa8
4 changed files with 23 additions and 2 deletions
|
@ -19,7 +19,7 @@ fn main() {
|
|||
let server = Wrapper::new(&irc_server);
|
||||
server.identify().unwrap();
|
||||
for message in server.iter() {
|
||||
let message = message.unwrap();
|
||||
let message = message.unwrap(); // We'll just panic if there's an error.
|
||||
print!("{}", message.into_string());
|
||||
if message.command[] == "PRIVMSG" {
|
||||
if let Some(msg) = message.suffix {
|
||||
|
|
|
@ -20,7 +20,7 @@ fn main() {
|
|||
let server = Wrapper::new(&irc_server);
|
||||
server.identify().unwrap();
|
||||
for message in server.iter() {
|
||||
let message = message.unwrap();
|
||||
let message = message.unwrap(); // We'll just panic if there's an error.
|
||||
print!("{}", message.into_string());
|
||||
if message.command[] == "PRIVMSG" {
|
||||
if let Some(msg) = message.suffix {
|
||||
|
|
10
src/conn.rs
10
src/conn.rs
|
@ -84,6 +84,16 @@ impl Connection<BufferedReader<NetStream>, BufferedWriter<NetStream>> {
|
|||
BufferedWriter::new(NetStream::SslTcpStream(ssl_socket)),
|
||||
))
|
||||
}
|
||||
|
||||
/// Sets the keepalive for the network stream.
|
||||
#[experimental]
|
||||
pub fn set_keepalive(&self, delay_in_seconds: Option<uint>) -> IoResult<()> {
|
||||
match self.reader.lock().get_mut() {
|
||||
&NetStream::UnsecuredTcpStream(ref mut tcp) => tcp.set_keepalive(delay_in_seconds),
|
||||
#[cfg(feature = "ssl")]
|
||||
&NetStream::SslTcpStream(ref mut ssl) => ssl.get_mut().set_keepalive(delay_in_seconds),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IrcReader, U: IrcWriter> Connection<T, U> {
|
||||
|
|
|
@ -81,6 +81,16 @@ impl IrcServer<BufferedReader<NetStream>, BufferedWriter<NetStream>> {
|
|||
alt_nick_index: RWLock::new(0u) })
|
||||
}
|
||||
|
||||
/// Reconnects to the IRC server.
|
||||
#[experimental]
|
||||
pub fn reconnect(&mut self) -> IoResult<()> {
|
||||
self.conn = try!(if self.config.use_ssl() {
|
||||
Connection::connect_ssl(self.config.server(), self.config.port())
|
||||
} else {
|
||||
Connection::connect(self.config.server(), self.config.port())
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: IrcReader, U: IrcWriter> Server<'a, T, U> for IrcServer<T, U> {
|
||||
|
@ -116,6 +126,7 @@ impl<T: IrcReader, U: IrcWriter> IrcServer<T, U> {
|
|||
}
|
||||
|
||||
/// Gets a reference to the IRC server's connection.
|
||||
#[experimental]
|
||||
pub fn conn(&self) -> &Connection<T, U> {
|
||||
&self.conn
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue