Added set_keepalive to Connection and the ability to reconnect to a

server.
This commit is contained in:
Aaron Weiss 2014-12-20 17:36:48 -05:00
parent 70031aa8d8
commit 3173accaa8
4 changed files with 23 additions and 2 deletions

View file

@ -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 {

View file

@ -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 {

View file

@ -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> {

View file

@ -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
}