Skip to content

Commit fc75724

Browse files
committed
[#698] Fix 'UnixDatagramSender' blocking send calls
1 parent 5157bb1 commit fc75724

File tree

3 files changed

+93
-8
lines changed

3 files changed

+93
-8
lines changed

doc/release-notes/iceoryx2-unreleased.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@
6969
[#608](https://github.com/eclipse-iceoryx/iceoryx2/issues/608)
7070
* Allow missing legal characters in system type for user- and group-name
7171
[#677](https://github.com/eclipse-iceoryx/iceoryx2/issues/677)
72-
* Fix `wait_and_process_once_with_timeout` deadlock
73-
[#695](https://github.com/eclipse-iceoryx/iceoryx2/issues/695)
7472
* Fix Miri issues with MetaVec due to temporary borrow
7573
[#682](https://github.com/eclipse-iceoryx/iceoryx2/issues/682)
74+
* Fix `wait_and_process_once_with_timeout` deadlock
75+
[#695](https://github.com/eclipse-iceoryx/iceoryx2/issues/695)
76+
* Fix `UnixDatagramSender` blocking send calls
77+
[#698](https://github.com/eclipse-iceoryx/iceoryx2/issues/698)
7678

7779
### Refactoring
7880

iceoryx2-bb/posix/src/unix_datagram_socket.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ impl UnixDatagramSender {
727727
/// If the data was sent it returns true, otherwise false.
728728
pub fn timed_send(&self, data: &[u8], timeout: Duration) -> Result<(), UnixDatagramSendError> {
729729
let msg = "Unable to timed send data";
730-
fail!(from self, when self.set_non_blocking(true),
730+
fail!(from self, when self.set_non_blocking(false),
731731
"{} since the socket could not bet set into blocking state.", msg);
732732
fail!(from self, when self.set_timeout(timeout),
733733
"{} since the socket timeout could not be set.", msg);
@@ -738,7 +738,7 @@ impl UnixDatagramSender {
738738
/// Blocks until the data was sent.
739739
pub fn blocking_send(&self, data: &[u8]) -> Result<(), UnixDatagramSendError> {
740740
let msg = "Unable to blocking send data";
741-
fail!(from self, when self.set_non_blocking(true),
741+
fail!(from self, when self.set_non_blocking(false),
742742
"{} since the socket could not bet set into blocking state.", msg);
743743
fail!(from self, when self.set_timeout(BLOCKING_TIMEOUT),
744744
"{} since the socket blocking timeout could not be set.", msg);

iceoryx2-bb/posix/tests/unix_datagram_socket_tests.rs

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use iceoryx2_bb_system_types::file_name::FileName;
2626
use iceoryx2_bb_system_types::file_path::FilePath;
2727
use iceoryx2_bb_testing::assert_that;
2828
use iceoryx2_bb_testing::test_requires;
29+
use iceoryx2_bb_testing::watchdog::Watchdog;
2930
use iceoryx2_pal_posix::posix::POSIX_SUPPORT_UNIX_DATAGRAM_SOCKETS_ANCILLARY_DATA;
3031
use std::thread;
3132
use std::time::Instant;
@@ -158,7 +159,9 @@ fn unix_datagram_socket_non_blocking_mode_returns_zero_when_nothing_was_received
158159
}
159160

160161
#[test]
161-
fn unix_datagram_socket_blocking_mode_blocks() {
162+
fn unix_datagram_socket_blocking_receive_blocks() {
163+
let _watchdog = Watchdog::new();
164+
162165
create_test_directory();
163166
let socket_name = generate_socket_name();
164167
let received_message = AtomicBool::new(false);
@@ -190,15 +193,95 @@ fn unix_datagram_socket_blocking_mode_blocks() {
190193
thread::sleep(TIMEOUT);
191194
let received_message_old = received_message.load(Ordering::Relaxed);
192195
sut_sender.blocking_send(send_data.as_slice()).unwrap();
193-
t.join().ok();
196+
t.join().unwrap();
194197

195198
assert_that!(received_message_old, eq false);
196199
assert_that!(received_message.load(Ordering::Relaxed), eq true);
197200
});
198201
}
199202

200203
#[test]
201-
fn unix_datagram_socket_timeout_blocks_at_least() {
204+
fn unix_datagram_socket_blocking_send_blocks() {
205+
let _watchdog = Watchdog::new();
206+
207+
create_test_directory();
208+
let socket_name = generate_socket_name();
209+
let handle = BarrierHandle::new();
210+
let handle_2 = BarrierHandle::new();
211+
let barrier = BarrierBuilder::new(2).create(&handle).unwrap();
212+
let barrier_2 = BarrierBuilder::new(2).create(&handle_2).unwrap();
213+
let send_data: Vec<u8> = vec![1u8, 3u8, 3u8, 7u8, 13u8, 73u8];
214+
215+
thread::scope(|s| {
216+
let t = s.spawn(|| {
217+
barrier.wait();
218+
let sut_sender = UnixDatagramSenderBuilder::new(&socket_name)
219+
.create()
220+
.unwrap();
221+
222+
while let Ok(true) = sut_sender.try_send(send_data.as_slice()) {}
223+
224+
let start = Instant::now();
225+
barrier_2.wait();
226+
227+
let result = sut_sender.blocking_send(send_data.as_slice());
228+
229+
assert_that!(result, is_ok);
230+
assert_that!(start.elapsed(), time_at_least TIMEOUT);
231+
});
232+
233+
let sut_receiver = UnixDatagramReceiverBuilder::new(&socket_name)
234+
.permission(Permission::OWNER_ALL)
235+
.creation_mode(CreationMode::PurgeAndCreate)
236+
.create()
237+
.unwrap();
238+
barrier.wait();
239+
barrier_2.wait();
240+
241+
thread::sleep(TIMEOUT);
242+
243+
let mut receive_data: Vec<u8> = vec![0, 0, 0, 0, 0, 0];
244+
while let Ok(count) = sut_receiver.try_receive(receive_data.as_mut_slice()) {
245+
if count == 0 {
246+
break;
247+
}
248+
}
249+
250+
t.join().unwrap();
251+
});
252+
}
253+
254+
#[test]
255+
fn unix_datagram_socket_timed_send_blocks_at_least_for_timeout() {
256+
let _watchdog = Watchdog::new();
257+
258+
create_test_directory();
259+
let socket_name = generate_socket_name();
260+
let send_data: Vec<u8> = vec![1u8, 3u8, 3u8, 7u8, 13u8, 173u8];
261+
262+
let _sut_receiver = UnixDatagramReceiverBuilder::new(&socket_name)
263+
.permission(Permission::OWNER_ALL)
264+
.creation_mode(CreationMode::PurgeAndCreate)
265+
.create()
266+
.unwrap();
267+
let sut_sender = UnixDatagramSenderBuilder::new(&socket_name)
268+
.create()
269+
.unwrap();
270+
271+
while let Ok(true) = sut_sender.try_send(send_data.as_slice()) {}
272+
273+
let start = Instant::now();
274+
275+
let result = sut_sender.timed_send(send_data.as_slice(), TIMEOUT);
276+
277+
assert_that!(result, is_ok);
278+
assert_that!(start.elapsed(), time_at_least TIMEOUT);
279+
}
280+
281+
#[test]
282+
fn unix_datagram_socket_timeout_receive_blocks_at_least_for_timeout() {
283+
let _watchdog = Watchdog::new();
284+
202285
create_test_directory();
203286
let socket_name = generate_socket_name();
204287
let handle = BarrierHandle::new();
@@ -226,7 +309,7 @@ fn unix_datagram_socket_timeout_blocks_at_least() {
226309
let start = Instant::now();
227310
barrier_2.wait();
228311

229-
t.join().ok();
312+
t.join().unwrap();
230313

231314
assert_that!(start.elapsed(), time_at_least TIMEOUT);
232315
});

0 commit comments

Comments
 (0)