Skip to content

Commit

Permalink
Make NNTPStream::connect generic
Browse files Browse the repository at this point in the history
This change makes it possible to pass non-static hostname to connect and
use non-IPv4 addresses.
  • Loading branch information
Alexander Krotov committed May 29, 2017
1 parent 3479db1 commit ca1e74c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate nntp;
use nntp::{Article, NNTPStream};

fn main() {
let mut nntp_stream = match NNTPStream::connect("nntp.aioe.org", 119) {
let mut nntp_stream = match NNTPStream::connect(("nntp.aioe.org", 119)) {
Ok(stream) => stream,
Err(e) => panic!("{}", e)
};
Expand Down
9 changes: 4 additions & 5 deletions src/nntp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
use std::string::String;
use std::io::{Read, Result, Error, ErrorKind, Write};
use std::net::TcpStream;
use std::net::ToSocketAddrs;
use std::vec::Vec;
use std::collections::HashMap;
use std::str::FromStr;

/// Stream to be used for interfacing with a NNTP server.
pub struct NNTPStream {
stream: TcpStream,
pub host: &'static str,
pub port: u16
}

pub struct Article {
Expand Down Expand Up @@ -67,9 +66,9 @@ impl NewsGroup {
impl NNTPStream {

/// Creates an NNTP Stream.
pub fn connect(host: &'static str, port: u16) -> Result<NNTPStream> {
let tcp_stream = try!(TcpStream::connect((host, port)));
let mut socket = NNTPStream { stream: tcp_stream, host: host, port: port };
pub fn connect<A: ToSocketAddrs>(addr: A) -> Result<NNTPStream> {
let tcp_stream = TcpStream::connect(addr)?;
let mut socket = NNTPStream { stream: tcp_stream };

match socket.read_response(200) {
Ok(_) => (),
Expand Down

0 comments on commit ca1e74c

Please sign in to comment.