diff --git a/OAT.xml b/OAT.xml
index 20cc6bcf29b94f463928597a092490b77d879495..95921d6e8b0383b369112e2734e084ea60e035be 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -22,8 +22,7 @@
-
-
\ No newline at end of file
+
diff --git a/libsync/include/sync.h b/libsync/include/sync.h
index cf0eabea86110bdda780ebacdf7ddc4114d69c5e..7f6adfac84d6bf36fb8b5a419e4edf38ca29bb3e 100644
--- a/libsync/include/sync.h
+++ b/libsync/include/sync.h
@@ -15,6 +15,6 @@
#ifndef COMM_UTILS_SYNC_H
#define COMM_UTILS_SYNC_H
-int SyncWait(int num, int time);
+int SyncWait(int fileDescriptor, int timeout);
-#endif
\ No newline at end of file
+#endif
diff --git a/libsync/src/sync.c b/libsync/src/sync.c
index 755df16ac18fbd3cbc4653bb550f8f590f94a1a9..8291466ae6c5c4a49377bdb5af457fca6e613b31 100644
--- a/libsync/src/sync.c
+++ b/libsync/src/sync.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 Google, Inc
+ * Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -17,32 +17,31 @@
#include
#include
-int SyncWait(int num, int time)
+int SyncWait(int fileDescriptor, int timeout)
{
- struct pollfd work;
- int result;
-
- if (num < 0) {
+ if (fileDescriptor < 0) {
errno = EINVAL;
return -1;
}
- work.fd = num;
- work.events = POLLIN;
+ struct pollfd pfd = { .fd = fileDescriptor, .events = POLLIN };
+ int pollResult;
+
+ while (1) {
+ pollResult = poll(&pfd, 1, timeout);
- do {
- result = poll(&work, 1, time);
- if (result > 0) {
- if (work.revents & (POLLERR | POLLNVAL)) {
+ if (pollResult > 0) {
+ if (pfd.revents & (POLLERR | POLLNVAL)) {
errno = EINVAL;
return -1;
}
return 0;
- } else if (result == 0) {
+ } else if (pollResult == 0) {
errno = ETIME;
return -1;
+ } else if (pollResult != -1 || (errno != EINTR && errno != EAGAIN)) {
+ break;
}
- } while (result == -1 && (errno == EINTR || errno == EAGAIN));
-
- return result;
+ }
+ return pollResult;
}