Skip to content

Commit 65d8404

Browse files
author
bors-servo
authored
Auto merge of #100 - emilio:fix-inprocess-oneshot, r=emilio,pcwalton
Fix inprocess oneshot Rebase of #90. @antrik sent a mail to the list saying he was not going to be active, so I took care of rebasing this.
2 parents 2422fde + db1f5a5 commit 65d8404

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/platform/inprocess/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ use std::usize;
2222

2323
use uuid::Uuid;
2424

25+
#[derive(Clone)]
2526
struct ServerRecord {
2627
sender: OsIpcSender,
2728
conn_sender: mpsc::Sender<bool>,
28-
conn_receiver: Mutex<mpsc::Receiver<bool>>,
29+
conn_receiver: Arc<Mutex<mpsc::Receiver<bool>>>,
2930
}
3031

3132
impl ServerRecord {
@@ -34,7 +35,7 @@ impl ServerRecord {
3435
ServerRecord {
3536
sender: sender,
3637
conn_sender: tx,
37-
conn_receiver: Mutex::new(rx),
38+
conn_receiver: Arc::new(Mutex::new(rx)),
3839
}
3940
}
4041

@@ -138,7 +139,7 @@ impl OsIpcSender {
138139
}
139140

140141
pub fn connect(name: String) -> Result<OsIpcSender,MpscError> {
141-
let record = ONE_SHOT_SERVERS.lock().unwrap().remove(&name).unwrap();
142+
let record = ONE_SHOT_SERVERS.lock().unwrap().get(&name).unwrap().clone();
142143
record.connect();
143144
Ok(record.sender)
144145
}
@@ -282,7 +283,9 @@ impl OsIpcOneShotServer {
282283
Vec<OsOpaqueIpcChannel>,
283284
Vec<OsIpcSharedMemory>),MpscError>
284285
{
285-
ONE_SHOT_SERVERS.lock().unwrap().get(&self.name).unwrap().accept();
286+
let record = ONE_SHOT_SERVERS.lock().unwrap().get(&self.name).unwrap().clone();
287+
record.accept();
288+
ONE_SHOT_SERVERS.lock().unwrap().remove(&self.name).unwrap();
286289
let receiver = self.receiver.borrow_mut().take().unwrap();
287290
let (data, channels, shmems) = receiver.recv().unwrap();
288291
Ok((receiver, data, channels, shmems))

src/platform/test.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use std::thread;
1515

1616
#[cfg(not(any(feature = "force-inprocess", target_os = "windows", target_os = "android")))]
1717
use libc;
18-
#[cfg(not(any(feature = "force-inprocess", target_os = "windows", target_os = "android")))]
1918
use platform::{OsIpcSender, OsIpcOneShotServer};
2019
#[cfg(not(any(feature = "force-inprocess", target_os = "windows", target_os = "android")))]
2120
use test::{fork, Wait};
@@ -396,10 +395,27 @@ fn receiver_set() {
396395
}
397396
}
398397

399-
#[cfg(not(any(feature = "force-inprocess", target_os = "windows", target_os = "android")))]
398+
#[cfg(not(any(feature = "force-inprocess", target_os = "android")))]
399+
#[test]
400+
fn server_accept_first() {
401+
let (server, name) = OsIpcOneShotServer::new().unwrap();
402+
let data: &[u8] = b"1234567";
403+
404+
thread::spawn(move || {
405+
thread::sleep(Duration::from_millis(30));
406+
let tx = OsIpcSender::connect(name).unwrap();
407+
tx.send(data, vec![], vec![]).unwrap();
408+
});
409+
410+
let (_, mut received_data, received_channels, received_shared_memory_regions) =
411+
server.accept().unwrap();
412+
received_data.truncate(7);
413+
assert_eq!((&received_data[..], received_channels, received_shared_memory_regions),
414+
(data, vec![], vec![]));
415+
}
416+
400417
#[test]
401-
//XXXjdm This hangs indefinitely with inprocess impl and warrants further investigation.
402-
fn server() {
418+
fn server_connect_first() {
403419
let (server, name) = OsIpcOneShotServer::new().unwrap();
404420
let data: &[u8] = b"1234567";
405421

@@ -408,6 +424,7 @@ fn server() {
408424
tx.send(data, vec![], vec![]).unwrap();
409425
});
410426

427+
thread::sleep(Duration::from_millis(30));
411428
let (_, mut received_data, received_channels, received_shared_memory_regions) =
412429
server.accept().unwrap();
413430
received_data.truncate(7);

0 commit comments

Comments
 (0)