Mercurial > templog
comparison rust/src/paramwaiter.rs @ 613:5c2b0d47bb83 rust
Response has epoch_tag and params
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 02 Mar 2017 00:06:20 +0800 |
parents | f3e39e2107fd |
children | e1bab5b36352 |
comparison
equal
deleted
inserted
replaced
612:5fc41e0833b4 | 613:5c2b0d47bb83 |
---|---|
7 use std::io; | 7 use std::io; |
8 use std::str; | 8 use std::str; |
9 use std::rc::Rc; | 9 use std::rc::Rc; |
10 use std::sync::{Arc,Mutex}; | 10 use std::sync::{Arc,Mutex}; |
11 use std::error::Error; | 11 use std::error::Error; |
12 use std::cell::Cell; | |
12 | 13 |
13 use tokio_core::reactor::Interval; | 14 use tokio_core::reactor::Interval; |
14 use tokio_core::reactor::Handle; | 15 use tokio_core::reactor::Handle; |
15 use tokio_curl::Session; | 16 use tokio_curl::Session; |
16 use futures::{Stream,Future,future}; | 17 use futures::{Stream,Future,future}; |
17 use curl::easy::Easy; | 18 use curl::easy::Easy; |
18 | 19 |
19 use types::*; | 20 use types::*; |
20 use ::Config; | 21 use ::Config; |
22 | |
23 #[derive(Deserialize, Debug)] | |
24 struct Response { | |
25 epoch_tag: String, | |
26 params: Params, | |
27 } | |
21 | 28 |
22 #[derive(Clone)] | 29 #[derive(Clone)] |
23 pub struct ParamWaiter { | 30 pub struct ParamWaiter { |
24 limitlog: NotTooOften, | 31 limitlog: NotTooOften, |
25 epoch_tag: String, | 32 epoch_tag: String, |
52 | 59 |
53 fn handle_response(&self, req: &mut Easy, buf: &Vec<u8>) -> Result<Option<Params>, TemplogError> { | 60 fn handle_response(&self, req: &mut Easy, buf: &Vec<u8>) -> Result<Option<Params>, TemplogError> { |
54 let text = String::from_utf8_lossy(buf).to_string(); | 61 let text = String::from_utf8_lossy(buf).to_string(); |
55 let resp = req.response_code()?; | 62 let resp = req.response_code()?; |
56 match resp { | 63 match resp { |
57 200 => Ok(Some(serde_json::from_str(&text)?)), // new params | 64 200 => { |
65 // new params | |
66 let r: Response = serde_json::from_str(&text)?; | |
67 // XXX | |
68 //self.epoch_tag = r.epoch_tag; | |
69 Ok(Some(r.params)) | |
70 } | |
58 304 => Ok(None), // unmodified (long polling timeout at the server) | 71 304 => Ok(None), // unmodified (long polling timeout at the server) |
59 _ => { | 72 _ => { |
60 Err(TemplogError::new(&format!("Wrong server response code {}: {}", resp, text))) | 73 Err(TemplogError::new(&format!("Wrong server response code {}: {}", resp, text))) |
61 }, | 74 }, |
62 } | 75 } |