@@ -202,39 +202,66 @@ pub fn download_file<P: AsRef<Path>>(url: hyper::Url,
202202 #[ derive( Clone ) ]
203203 struct NativeSslStream < T > ( Arc < Mutex < native_tls:: TlsStream < T > > > ) ;
204204
205+ #[ derive( Debug ) ]
206+ struct NativeSslPoisonError ;
207+
208+ impl :: std:: error:: Error for NativeSslPoisonError {
209+ fn description ( & self ) -> & str { "mutex poisoned during TLS operation" }
210+ }
211+
212+ impl :: std:: fmt:: Display for NativeSslPoisonError {
213+ fn fmt ( & self , f : & mut :: std:: fmt:: Formatter ) -> :: std:: result:: Result < ( ) , :: std:: fmt:: Error > {
214+ f. write_str ( :: std:: error:: Error :: description ( self ) )
215+ }
216+ }
217+
205218 impl < T > NetworkStream for NativeSslStream < T >
206219 where T : NetworkStream
207220 {
208221 fn peer_addr ( & mut self ) -> IoResult < SocketAddr > {
209- self . 0 . lock ( ) . expect ( "" ) . get_mut ( ) . peer_addr ( )
222+ self . 0 . lock ( )
223+ . map_err ( |_| io:: Error :: new ( io:: ErrorKind :: Other , NativeSslPoisonError ) )
224+ . and_then ( |mut t| t. get_mut ( ) . peer_addr ( ) )
210225 }
211226 fn set_read_timeout ( & self , dur : Option < Duration > ) -> IoResult < ( ) > {
212- self . 0 . lock ( ) . expect ( "" ) . get_ref ( ) . set_read_timeout ( dur)
227+ self . 0 . lock ( )
228+ . map_err ( |_| io:: Error :: new ( io:: ErrorKind :: Other , NativeSslPoisonError ) )
229+ . and_then ( |t| t. get_ref ( ) . set_read_timeout ( dur) )
213230 }
214231 fn set_write_timeout ( & self , dur : Option < Duration > ) -> IoResult < ( ) > {
215- self . 0 . lock ( ) . expect ( "" ) . get_ref ( ) . set_read_timeout ( dur)
232+ self . 0 . lock ( )
233+ . map_err ( |_| io:: Error :: new ( io:: ErrorKind :: Other , NativeSslPoisonError ) )
234+ . and_then ( |t| t. get_ref ( ) . set_write_timeout ( dur) )
216235 }
217236 fn close ( & mut self , how : Shutdown ) -> IoResult < ( ) > {
218- self . 0 . lock ( ) . expect ( "" ) . get_mut ( ) . close ( how)
237+ self . 0 . lock ( )
238+ . map_err ( |_| io:: Error :: new ( io:: ErrorKind :: Other , NativeSslPoisonError ) )
239+ . and_then ( |mut t| t. get_mut ( ) . close ( how) )
219240 }
220241 }
221242
222243 impl < T > Read for NativeSslStream < T >
223244 where T : Read + Write
224245 {
225246 fn read ( & mut self , buf : & mut [ u8 ] ) -> IoResult < usize > {
226- self . 0 . lock ( ) . expect ( "" ) . read ( buf)
247+ self . 0 . lock ( )
248+ . map_err ( |_| io:: Error :: new ( io:: ErrorKind :: Other , NativeSslPoisonError ) )
249+ . and_then ( |mut t| t. read ( buf) )
227250 }
228251 }
229252
230253 impl < T > Write for NativeSslStream < T >
231254 where T : Read + Write
232255 {
233256 fn write ( & mut self , buf : & [ u8 ] ) -> IoResult < usize > {
234- self . 0 . lock ( ) . expect ( "" ) . write ( buf)
257+ self . 0 . lock ( )
258+ . map_err ( |_| io:: Error :: new ( io:: ErrorKind :: Other , NativeSslPoisonError ) )
259+ . and_then ( |mut t| t. write ( buf) )
235260 }
236261 fn flush ( & mut self ) -> IoResult < ( ) > {
237- self . 0 . lock ( ) . expect ( "" ) . flush ( )
262+ self . 0 . lock ( )
263+ . map_err ( |_| io:: Error :: new ( io:: ErrorKind :: Other , NativeSslPoisonError ) )
264+ . and_then ( |mut t| t. flush ( ) )
238265 }
239266 }
240267
0 commit comments