fn wnbind_try(cmd: &str, arg: &str) -> NssResult<String> {

    // connect to webnis-bind.
    let mut socket = match UnixStream::connect(SOCKADDR) {
        Ok(s) => s,
        Err(e) => {
            debug!("connect to {}: {}", SOCKADDR, e);
            return Err(e)?;
        },
    };
    socket.set_read_timeout(Some(Duration::from_millis(REQUEST_READ_TIMEOUT_MS))).ok();
    socket.set_write_timeout(Some(Duration::from_millis(REQUEST_WRITE_TIMEOUT_MS))).ok();

    // send request.
    let b = format!("{} {}\n", cmd, arg).into_bytes();
    if let Err(e) = socket.write_all(&b) {
        debug!("write to {}: {}", SOCKADDR, e);
        return Err(e)?;
    }

    // get reply.
    let mut line = String::new();
    let mut rdr = BufReader::new(socket);
    if let Err(e) = rdr.read_line(&mut line) {
        debug!("reading from {}: {}", SOCKADDR, e);
        return Err(e)?;
    }

    // split into reply-code and message-text
    let mut s = line.trim_right().splitn(2, ' ');
    let num = s.next().unwrap();
    let val = s.next().unwrap_or("");

    let code = match num.parse::<u16>() {
        Ok(c) => c,
        Err(_) => {
            debug!("error: got garbage answer [{}]", num);
            return Err(NssError::Unavailable);
        },
    };

    match code {
        200 ... 299 => {
            Ok(val.to_string())
        },
        401 => Err(NssError::Unavailable),
        403 => Err(NssError::Unavailable),
        404 => Err(NssError::NotFound),
        400 ... 499 => {
            debug!("error: {}", line);
            Err(NssError::TryAgainLater)
        },
        _ => {
            debug!("error: {}", line);
            Err(NssError::Unavailable)
        }
    }
}
// open socket, send one command, read reply, return.
open socket, send one command, read reply, return.
open socket send one command read reply return .
fn wnbind_try(cmd: &str, arg: &str) -> NssResult<String> {
    // connect to webnis-bind.
    let mut socket = match UnixStream::connect(SOCKADDR) {
        Ok(s) => s,
        Err(e) => {
            debug!("connect to {}: {}", SOCKADDR, e);
            return Err(e)?;
        },
    };
    socket.set_read_timeout(Some(Duration::from_millis(REQUEST_READ_TIMEOUT_MS))).ok();
    socket.set_write_timeout(Some(Duration::from_millis(REQUEST_WRITE_TIMEOUT_MS))).ok();
    // send request.
    let b = format!("{} {}\n", cmd, arg).into_bytes();
    if let Err(e) = socket.write_all(&b) {
        debug!("write to {}: {}", SOCKADDR, e);
        return Err(e)?;
    }
    // get reply.
    let mut line = String::new();
    let mut rdr = BufReader::new(socket);
    if let Err(e) = rdr.read_line(&mut line) {
        debug!("reading from {}: {}", SOCKADDR, e);
        return Err(e)?;
    }
    // split into reply-code and message-text
    let mut s = line.trim_right().splitn(2, ' ');
    let num = s.next().unwrap();
    let val = s.next().unwrap_or("");
    let code = match num.parse::<u16>() {
        Ok(c) => c,
        Err(_) => {
            debug!("error: got garbage answer [{}]", num);
            return Err(NssError::Unavailable);
        },
    };
    match code {
        200 ... 299 => {
            Ok(val.to_string())
        },
        401 => Err(NssError::Unavailable),
        403 => Err(NssError::Unavailable),
        404 => Err(NssError::NotFound),
        400 ... 499 => {
            debug!("error: {}", line);
            Err(NssError::TryAgainLater)
        },
        _ => {
            debug!("error: {}", line);
            Err(NssError::Unavailable)
        }
    }
}
fn wnbind_try ( cmd : & str , arg : & str ) -> NssResult < String > { // connect to webnis-bind. let mut socket = match UnixStream :: connect ( SOCKADDR ) { Ok ( s ) => s , Err ( e ) => { debug ! ( " " SOCKADDR e ) ; return Err ( e ) ? ; } , } ; socket . set_read_timeout ( Some ( Duration :: from_millis ( REQUEST_READ_TIMEOUT_MS ) ) ) . ok ( ) ; socket . set_write_timeout ( Some ( Duration :: from_millis ( REQUEST_WRITE_TIMEOUT_MS ) ) ) . ok ( ) ; // send request. let b = format ! ( " \n " cmd arg ) . into_bytes ( ) ; if let Err ( e ) = socket . write_all ( & b ) { debug ! ( " " SOCKADDR e ) ; return Err ( e ) ? ; } // get reply. let mut line = String :: new ( ) ; let mut rdr = BufReader :: new ( socket ) ; if let Err ( e ) = rdr . read_line ( & mut line ) { debug ! ( " " SOCKADDR e ) ; return Err ( e ) ? ; } // split into reply-code and message-text let mut s = line . trim_right ( ) . splitn ( 2 , ' ' ) ; let num = s . next ( ) . unwrap ( ) ; let val = s . next ( ) . unwrap_or ( " " ) ; let code = match num . parse :: < u16 > ( ) { Ok ( c ) => c , Err ( _ ) => { debug ! ( " " num ) ; return Err ( NssError :: Unavailable ) ; } , } ; match code { 200 ... 299 => { Ok ( val . to_string ( ) ) } , 401 => Err ( NssError :: Unavailable ) , 403 => Err ( NssError :: Unavailable ) , 404 => Err ( NssError :: NotFound ) , 400 ... 499 => { debug ! ( " " line ) ; Err ( NssError :: TryAgainLater ) } , _ => { debug ! ( " " line ) ; Err ( NssError :: Unavailable ) } } }
open socket, send one command, read reply, return.
open socket send one command read reply return .
cmd
&str
arg
&str