webdriver: server: return hyper::server::Listening so user can access socket addr (#41)
authorAndreas Tolfsen <ato@mozilla.com>
Tue, 06 Sep 2016 15:19:01 +0100
changeset 428079 927a2506de17048b8df65a92ee10a56cab04db18
parent 428078 ec76c768541f5a4a535bb868a3cdc2aa3b4a6851
child 428080 6824674691b0dba8749a940e028b3d4aa0c52895
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
webdriver: server: return hyper::server::Listening so user can access socket addr (#41) Source-Repo: https://github.com/mozilla/webdriver-rust Source-Revision: e23f83e5aebb19acd9566b8dbe69062ae963871d committer: jgraham <james@hoppipolla.co.uk>
testing/webdriver/src/server.rs
--- a/testing/webdriver/src/server.rs
+++ b/testing/webdriver/src/server.rs
@@ -1,20 +1,21 @@
+use std::io::Read;
 use std::marker::PhantomData;
-use std::io::Read;
+use std::net::SocketAddr;
+use std::sync::mpsc::{channel, Receiver, Sender};
 use std::sync::Mutex;
-use std::sync::mpsc::{channel, Receiver, Sender};
 use std::thread;
-use std::net::SocketAddr;
 
 use hyper::header::ContentType;
 use hyper::method::Method;
-use hyper::server::{Server, Handler, Request, Response};
+use hyper::Result;
+use hyper::server::{Handler, Listening, Request, Response, Server};
+use hyper::status::StatusCode;
 use hyper::uri::RequestUri::AbsolutePath;
-use hyper::status::StatusCode;
 
 use command::{WebDriverMessage, WebDriverCommand};
 use error::{WebDriverResult, WebDriverError, ErrorStatus};
 use httpapi::{WebDriverHttpApi, WebDriverExtensionRoute, VoidWebDriverExtensionRoute};
 use response::WebDriverResponse;
 
 enum DispatchMessage<U: WebDriverExtensionRoute> {
     HandleWebDriver(WebDriverMessage<U>, Sender<WebDriverResult<WebDriverResponse>>),
@@ -224,26 +225,31 @@ impl <U: WebDriverExtensionRoute> Handle
                 res.headers_mut().set(ContentType::json());
                 res.send(&resp_body.as_bytes()).unwrap();
             },
             _ => {}
         }
     }
 }
 
-pub fn start<T: 'static+WebDriverHandler<U>,
-             U: 'static+WebDriverExtensionRoute>(address: SocketAddr,
-                                                 handler: T,
-                                                 extension_routes:Vec<(Method, &str, U)>) {
+pub fn start<T, U>(address: SocketAddr,
+                   handler: T,
+                   extension_routes: Vec<(Method, &str, U)>)
+                   -> Result<Listening>
+    where T: 'static + WebDriverHandler<U>,
+          U: 'static + WebDriverExtensionRoute
+{
     let (msg_send, msg_recv) = channel();
 
     let api = WebDriverHttpApi::new(extension_routes);
     let http_handler = HttpHandler::new(api, msg_send);
     let mut server = Server::http(address).unwrap();
     server.keep_alive(None);
 
     let builder = thread::Builder::new().name("webdriver dispatcher".to_string());
     builder.spawn(move || {
-        let mut dispatcher = Dispatcher::new(handler);
-        dispatcher.run(msg_recv)
-    }).unwrap();
-    server.handle(http_handler).unwrap();
+            let mut dispatcher = Dispatcher::new(handler);
+            dispatcher.run(msg_recv);
+        })
+        .unwrap();
+
+    server.handle(http_handler)
 }