@@ -84,8 +84,18 @@ Api::IoCallUint64Result IoSocketHandleImpl::readv(uint64_t max_length, Buffer::R
84
84
num_bytes_to_read += slice_length;
85
85
}
86
86
ASSERT (num_bytes_to_read <= max_length);
87
- return sysCallResultToIoCallResult (Api::OsSysCallsSingleton::get ().readv (
87
+ auto result = sysCallResultToIoCallResult (Api::OsSysCallsSingleton::get ().readv (
88
88
fd_, iov.begin (), static_cast <int >(num_slices_to_read)));
89
+
90
+ // Emulated edge events need to registered if the socket operation did not complete
91
+ // because the socket would block.
92
+ if constexpr (Event::PlatformDefaultTriggerType == Event::FileTriggerType::EmulatedEdge) {
93
+ // Some tests try to read without initializing the file_event.
94
+ if (result.wouldBlock () && file_event_) {
95
+ file_event_->registerEventIfEmulatedEdge (Event::FileReadyType::Read);
96
+ }
97
+ }
98
+ return result;
89
99
}
90
100
91
101
Api::IoCallUint64Result IoSocketHandleImpl::read (Buffer::Instance& buffer, uint64_t max_length) {
@@ -103,6 +113,15 @@ Api::IoCallUint64Result IoSocketHandleImpl::read(Buffer::Instance& buffer, uint6
103
113
bytes_to_commit -= slices[i].len_ ;
104
114
}
105
115
buffer.commit (slices, num_slices);
116
+
117
+ // Emulated edge events need to registered if the socket operation did not complete
118
+ // because the socket would block.
119
+ if constexpr (Event::PlatformDefaultTriggerType == Event::FileTriggerType::EmulatedEdge) {
120
+ // Some tests try to read without initializing the file_event.
121
+ if (result.wouldBlock () && file_event_) {
122
+ file_event_->registerEventIfEmulatedEdge (Event::FileReadyType::Read);
123
+ }
124
+ }
106
125
return result;
107
126
}
108
127
@@ -120,8 +139,18 @@ Api::IoCallUint64Result IoSocketHandleImpl::writev(const Buffer::RawSlice* slice
120
139
if (num_slices_to_write == 0 ) {
121
140
return Api::ioCallUint64ResultNoError ();
122
141
}
123
- return sysCallResultToIoCallResult (
142
+ auto result = sysCallResultToIoCallResult (
124
143
Api::OsSysCallsSingleton::get ().writev (fd_, iov.begin (), num_slices_to_write));
144
+
145
+ // Emulated edge events need to registered if the socket operation did not complete
146
+ // because the socket would block.
147
+ if constexpr (Event::PlatformDefaultTriggerType == Event::FileTriggerType::EmulatedEdge) {
148
+ // Some tests try to write without initializing the file_event.
149
+ if (result.wouldBlock () && file_event_) {
150
+ file_event_->registerEventIfEmulatedEdge (Event::FileReadyType::Write);
151
+ }
152
+ }
153
+ return result;
125
154
}
126
155
127
156
Api::IoCallUint64Result IoSocketHandleImpl::write (Buffer::Instance& buffer) {
@@ -131,6 +160,15 @@ Api::IoCallUint64Result IoSocketHandleImpl::write(Buffer::Instance& buffer) {
131
160
if (result.ok () && result.rc_ > 0 ) {
132
161
buffer.drain (static_cast <uint64_t >(result.rc_ ));
133
162
}
163
+
164
+ // Emulated edge events need to registered if the socket operation did not complete
165
+ // because the socket would block.
166
+ if constexpr (Event::PlatformDefaultTriggerType == Event::FileTriggerType::EmulatedEdge) {
167
+ // Some tests try to read without initializing the file_event.
168
+ if (result.wouldBlock () && file_event_) {
169
+ file_event_->registerEventIfEmulatedEdge (Event::FileReadyType::Write);
170
+ }
171
+ }
134
172
return result;
135
173
}
136
174
@@ -168,7 +206,15 @@ Api::IoCallUint64Result IoSocketHandleImpl::sendmsg(const Buffer::RawSlice* slic
168
206
message.msg_control = nullptr ;
169
207
message.msg_controllen = 0 ;
170
208
const Api::SysCallSizeResult result = os_syscalls.sendmsg (fd_, &message, flags);
171
- return sysCallResultToIoCallResult (result);
209
+ auto io_result = sysCallResultToIoCallResult (result);
210
+ // Emulated edge events need to registered if the socket operation did not complete
211
+ // because the socket would block.
212
+ if constexpr (Event::PlatformDefaultTriggerType == Event::FileTriggerType::EmulatedEdge) {
213
+ if (io_result.wouldBlock () && file_event_) {
214
+ file_event_->registerEventIfEmulatedEdge (Event::FileReadyType::Write);
215
+ }
216
+ }
217
+ return io_result;
172
218
} else {
173
219
const size_t space_v6 = CMSG_SPACE (sizeof (in6_pktinfo));
174
220
const size_t space_v4 = CMSG_SPACE (sizeof (in_pktinfo));
@@ -210,7 +256,15 @@ Api::IoCallUint64Result IoSocketHandleImpl::sendmsg(const Buffer::RawSlice* slic
210
256
*(reinterpret_cast <absl::uint128*>(pktinfo->ipi6_addr .s6_addr )) = self_ip->ipv6 ()->address ();
211
257
}
212
258
const Api::SysCallSizeResult result = os_syscalls.sendmsg (fd_, &message, flags);
213
- return sysCallResultToIoCallResult (result);
259
+ auto io_result = sysCallResultToIoCallResult (result);
260
+ // Emulated edge events need to registered if the socket operation did not complete
261
+ // because the socket would block.
262
+ if constexpr (Event::PlatformDefaultTriggerType == Event::FileTriggerType::EmulatedEdge) {
263
+ if (io_result.wouldBlock () && file_event_) {
264
+ file_event_->registerEventIfEmulatedEdge (Event::FileReadyType::Write);
265
+ }
266
+ }
267
+ return io_result;
214
268
}
215
269
}
216
270
@@ -298,7 +352,15 @@ Api::IoCallUint64Result IoSocketHandleImpl::recvmsg(Buffer::RawSlice* slices,
298
352
hdr.msg_controllen = cmsg_space_;
299
353
const Api::SysCallSizeResult result = Api::OsSysCallsSingleton::get ().recvmsg (fd_, &hdr, 0 );
300
354
if (result.rc_ < 0 ) {
301
- return sysCallResultToIoCallResult (result);
355
+ auto io_result = sysCallResultToIoCallResult (result);
356
+ // Emulated edge events need to registered if the socket operation did not complete
357
+ // because the socket would block.
358
+ if constexpr (Event::PlatformDefaultTriggerType == Event::FileTriggerType::EmulatedEdge) {
359
+ if (io_result.wouldBlock () && file_event_) {
360
+ file_event_->registerEventIfEmulatedEdge (Event::FileReadyType::Read);
361
+ }
362
+ }
363
+ return io_result;
302
364
}
303
365
304
366
RELEASE_ASSERT ((hdr.msg_flags & MSG_CTRUNC) == 0 ,
@@ -381,7 +443,15 @@ Api::IoCallUint64Result IoSocketHandleImpl::recvmmsg(RawSliceArrays& slices, uin
381
443
fd_, mmsg_hdr.data (), num_packets_per_mmsg_call, MSG_TRUNC | MSG_WAITFORONE, nullptr );
382
444
383
445
if (result.rc_ <= 0 ) {
384
- return sysCallResultToIoCallResult (result);
446
+ auto io_result = sysCallResultToIoCallResult (result);
447
+ // Emulated edge events need to registered if the socket operation did not complete
448
+ // because the socket would block.
449
+ if constexpr (Event::PlatformDefaultTriggerType == Event::FileTriggerType::EmulatedEdge) {
450
+ if (io_result.wouldBlock () && file_event_) {
451
+ file_event_->registerEventIfEmulatedEdge (Event::FileReadyType::Read);
452
+ }
453
+ }
454
+ return io_result;
385
455
}
386
456
387
457
int num_packets_read = result.rc_ ;
@@ -435,7 +505,15 @@ Api::IoCallUint64Result IoSocketHandleImpl::recvmmsg(RawSliceArrays& slices, uin
435
505
Api::IoCallUint64Result IoSocketHandleImpl::recv (void * buffer, size_t length, int flags) {
436
506
const Api::SysCallSizeResult result =
437
507
Api::OsSysCallsSingleton::get ().recv (fd_, buffer, length, flags);
438
- return sysCallResultToIoCallResult (result);
508
+ auto io_result = sysCallResultToIoCallResult (result);
509
+ // Emulated edge events need to registered if the socket operation did not complete
510
+ // because the socket would block.
511
+ if constexpr (Event::PlatformDefaultTriggerType == Event::FileTriggerType::EmulatedEdge) {
512
+ if (io_result.wouldBlock () && file_event_) {
513
+ file_event_->registerEventIfEmulatedEdge (Event::FileReadyType::Read);
514
+ }
515
+ }
516
+ return io_result;
439
517
}
440
518
441
519
bool IoSocketHandleImpl::supportsMmsg () const {
0 commit comments