Skip to content

Commit e5f036d

Browse files
committed
Fix some minor points according to the comments.
1 parent ac73400 commit e5f036d

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ fn create_util_map() -> HashMap<&'static str, &'static str> {
2525
hashmap.insert("tar", "lsb");
2626

2727
hashmap.insert("ping", "networking");
28+
hashmap.insert("nc", "networking");
2829

2930
hashmap.insert("cat", "posix");
3031
hashmap.insert("chmod", "posix");
3132
hashmap.insert("head", "posix");
3233
hashmap.insert("sh", "posix");
3334
hashmap.insert("sleep", "posix");
34-
hashmap.insert("nc", "networking");
3535

3636
hashmap.insert("init", "sysinit");
3737

src/networking/nc/mod.rs

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
extern crate mio;
22
extern crate clap;
3-
extern crate libc;
43
extern crate socket2;
54

65
use std;
@@ -10,7 +9,7 @@ use clap::{Arg, ArgMatches};
109
use mio::{Events, Event, Poll, Ready, PollOpt, Token};
1110
use libc::{AF_UNSPEC, AF_INET, AF_INET6, AF_UNIX};
1211
use std::io;
13-
use std::net::{SocketAddr};
12+
use std::net::SocketAddr;
1413
use mio::unix::EventedFd;
1514
use std::io::{Read,Write, ErrorKind};
1615
use mio::unix::UnixReady;
@@ -81,10 +80,10 @@ fn debug_info(msg: &str) {
8180

8281
impl NcOptions {
8382
pub fn parse(matches: ArgMatches, msg: &str) -> Result<NcOptions, MesaError> {
84-
let mut portlist = vec!();
83+
let mut portlist = vec![];
8584
let lflag = matches.is_present("l");
8685
let mut host = String::from("127.0.0.1");
87-
let uport:String;
86+
let uport: String;
8887
let mut interval = None;
8988
let mut timeout = None;
9089
let s_addr = match matches.value_of("s") {
@@ -98,11 +97,7 @@ impl NcOptions {
9897
let kflag = matches.is_present("k");
9998

10099
/* Cruft to make sure options are clean, and used properly. */
101-
let positionals: Vec<&str> = if matches.is_present("positionals") {
102-
matches.values_of("positionals").unwrap().collect()
103-
} else {
104-
vec!()
105-
};
100+
let positionals:Vec<&str> = matches.values_of("positionals").unwrap().collect();
106101

107102
let family = if matches.is_present("U") {
108103
AF_UNIX
@@ -128,7 +123,7 @@ impl NcOptions {
128123
host = String::from(positionals[0]);
129124
uport = String::from(positionals[1]);
130125
} else {
131-
return mesaerr_result(msg);
126+
unreachable!()
132127
}
133128

134129
if lflag && s_addr.is_some() {
@@ -345,7 +340,7 @@ impl <'a> NcCore<'a> {
345340
} else if self.stdinbuf_full() {
346341
self.disable_stdin()?;
347342
}
348-
}
343+
}
349344

350345
// if net writable and buf not empty, try to write to net
351346
// error, stop watching for netout
@@ -444,81 +439,81 @@ impl <'a> NcCore<'a> {
444439
self.netinbufpos >= BUFSIZE
445440
}
446441

447-
fn remove_stdin(&mut self) -> std::io::Result<()> {
442+
fn remove_stdin(&mut self) -> io::Result<()> {
448443
remove_item(&mut self.open_ends, NcCore::STDIN_POLL);
449444
self.poll.deregister(&self.event_stdin)
450445
}
451446

452-
fn remove_stdout(&mut self) -> std::io::Result<()> {
447+
fn remove_stdout(&mut self) -> io::Result<()> {
453448
debug_info("remove_stdout");
454449
remove_item(&mut self.open_ends, NcCore::STDOUT_POLL);
455450
self.poll.deregister(&self.event_stdout)
456451
}
457452

458-
fn remove_netin(&mut self) -> std::io::Result<()> {
453+
fn remove_netin(&mut self) -> io::Result<()> {
459454
remove_item(&mut self.open_ends, NcCore::NETIN_POLL);
460455
self.net_interest.remove(Ready::readable());
461456
self.reregister_net()
462457
}
463458

464-
fn remove_netout(&mut self) -> std::io::Result<()> {
459+
fn remove_netout(&mut self) -> io::Result<()> {
465460
remove_item(&mut self.open_ends, NcCore::NETOUT_POLL);
466461
self.net_interest.remove(Ready::writable());
467462
return self.reregister_net();
468463
}
469464

470-
fn reregister_net(&mut self) -> std::io::Result<()> {
465+
fn reregister_net(&mut self) -> io::Result<()> {
471466
self.poll.reregister(&self.event_net, NcCore::TK_NET, self.net_interest,
472467
PollOpt::empty())
473468
}
474469

475-
fn enable_netin(&mut self) -> std::io::Result<()>{
470+
fn enable_netin(&mut self) -> io::Result<()>{
476471
self.net_interest |= Ready::readable();
477472
self.reregister_net()
478473
}
479474

480-
fn disable_netin(&mut self) -> std::io::Result<()>{
475+
fn disable_netin(&mut self) -> io::Result<()>{
481476
self.net_interest.remove(Ready::readable());
482-
self.reregister_net()
477+
self.reregister_net()
483478
}
484479

485-
fn enable_netout(&mut self) -> std::io::Result<()> {
480+
fn enable_netout(&mut self) -> io::Result<()> {
486481
self.net_interest |= Ready::writable();
487-
self.reregister_net()
482+
self.reregister_net()
488483
}
489484

490-
fn disable_netout(&mut self) -> std::io::Result<()> {
485+
fn disable_netout(&mut self) -> io::Result<()> {
491486
self.net_interest.remove(Ready::writable());
492-
self.reregister_net()
487+
self.reregister_net()
493488
}
494489

495-
fn enable_stdin(&mut self) -> std::io::Result<()> {
490+
fn enable_stdin(&mut self) -> io::Result<()> {
496491
self.poll.reregister(&self.event_stdin, NcCore::TK_STDIN, Ready::readable(),
497492
PollOpt::empty())
498493
}
499494

500-
fn disable_stdin(&mut self) -> std::io::Result<()> {
495+
fn disable_stdin(&mut self) -> io::Result<()> {
501496
self.poll.reregister(&self.event_stdin, NcCore::TK_STDIN, Ready::empty(),
502497
PollOpt::empty())
503498
}
504499

505-
fn enable_stdout(&mut self) -> std::io::Result<()> {
500+
fn enable_stdout(&mut self) -> io::Result<()> {
506501
self.poll.reregister(&self.event_stdout, NcCore::TK_STDOUT, Ready::writable(),
507502
PollOpt::empty())
508503
}
509504

510-
fn disable_stdout(&mut self) -> std::io::Result<()> {
505+
fn disable_stdout(&mut self) -> io::Result<()> {
511506
self.poll.reregister(&self.event_stdout, NcCore::TK_STDOUT, Ready::empty(),
512507
PollOpt::empty())
513508
}
514509

515-
fn remove_net(&mut self) -> std::io::Result<()> {
510+
fn remove_net(&mut self) -> io::Result<()> {
516511
remove_item(&mut self.open_ends, NcCore::NETIN_POLL);
517512
remove_item(&mut self.open_ends, NcCore::NETOUT_POLL);
518513
self.poll.deregister(&self.event_net)
519514
}
520515

521-
fn read_stdin(&mut self) -> std::io::Result<()> {
516+
fn read_stdin(&mut self) -> io::Result<()> {
522517
let mut remove = false;
523518
match io::stdin().read(&mut self.stdinbuf[self.stdinbufpos..]) {
524519
Ok(len) => {
@@ -538,7 +533,7 @@ impl <'a> NcCore<'a> {
538533
Ok(())
539534
}
540535

541-
fn write_netout(&mut self) -> std::io::Result<()> {
536+
fn write_netout(&mut self) -> io::Result<()> {
542537
let mut remove = false;
543538
match self.sock.write(&mut self.stdinbuf[0..self.stdinbufpos]) {
544539
Ok(len) => {
@@ -567,7 +562,7 @@ impl <'a> NcCore<'a> {
567562
Ok(())
568563
}
569564

570-
fn read_netin(&mut self) -> std::io::Result<()> {
565+
fn read_netin(&mut self) -> io::Result<()> {
571566
let mut remove = false;
572567
match self.sock.read(&mut self.netinbuf[self.netinbufpos..]) {
573568
Ok(len) => {
@@ -587,7 +582,7 @@ impl <'a> NcCore<'a> {
587582
Ok(())
588583
}
589584

590-
fn write_stdout(&mut self) -> std::io::Result<()> {
585+
fn write_stdout(&mut self) -> io::Result<()> {
591586
let mut remove = false;
592587
match io::stdout().write(&mut self.netinbuf[0..self.netinbufpos]) {
593588
Ok(len) => {
@@ -607,14 +602,14 @@ impl <'a> NcCore<'a> {
607602
_ => remove = true
608603
}
609604
},
610-
}
605+
}
611606
if remove {
612607
return self.remove_stdout();
613608
}
614-
Ok(())
609+
Ok(())
615610
}
616611

617-
fn handle_error_event(&mut self, event: &Event) -> std::io::Result<()> {
612+
fn handle_error_event(&mut self, event: &Event) -> io::Result<()> {
618613
match event.token() {
619614
NcCore::TK_STDIN => self.remove_stdin(),
620615
NcCore::TK_STDOUT => self.remove_stdout(),
@@ -623,7 +618,7 @@ impl <'a> NcCore<'a> {
623618
}
624619
}
625620

626-
fn handle_hup_event(&mut self, event: &Event) -> std::io::Result<()> {
621+
fn handle_hup_event(&mut self, event: &Event) -> io::Result<()> {
627622
if !self.stdin_gone() && event.token() == NcCore::TK_STDIN &&
628623
!event.readiness().is_readable() {
629624
self.remove_stdin()?
@@ -667,7 +662,7 @@ impl <'a> NcCore<'a> {
667662
debug_info(&format!("new_ready_end {:?}", new_ready_end));
668663
}
669664
}
670-
*last_ready_end = new_ready_end;
665+
*last_ready_end = new_ready_end;
671666
}
672667
}
673668

@@ -910,9 +905,9 @@ where
910905
.takes_value(true))
911906
.arg(Arg::with_name("s")
912907
.short("s")
913-
.value_name("source_ip_address")
908+
.value_name("source_ip_address")
914909
.takes_value(true)
915-
.help("Specifies the IP of the interface which is used to send the packets. It is an error to use this option in conjunction with the -l option."))
910+
.help("Specifies the IP of the interface which is used to send the packets. It is an error to use this option in conjunction with the -l option."))
916911
.arg(Arg::with_name("d")
917912
.short("d")
918913
.help("Do not attempt to read from stdin."))

0 commit comments

Comments
 (0)