Browse Source

faux.net: faux_pollfd_del_by_... functions return bool_t instead int

Serj Kalichev 3 years ago
parent
commit
bf25bebb92
3 changed files with 19 additions and 13 deletions
  1. 1 1
      faux/eloop/eloop.c
  2. 2 2
      faux/net.h
  3. 16 10
      faux/net/pollfd.c

+ 1 - 1
faux/eloop/eloop.c

@@ -401,7 +401,7 @@ bool_t faux_eloop_del_fd(faux_eloop_t *eloop, int fd)
 	if (faux_list_kdel(eloop->fds, &fd) < 0)
 		return BOOL_FALSE;
 
-	if (faux_pollfd_del_by_fd(eloop->pollfds, fd) < 0)
+	if (!faux_pollfd_del_by_fd(eloop->pollfds, fd))
 		return BOOL_FALSE;
 
 	return BOOL_TRUE;

+ 2 - 2
faux/net.h

@@ -64,8 +64,8 @@ size_t faux_pollfd_len(faux_pollfd_t *faux_pollfd);
 struct pollfd *faux_pollfd_item(faux_pollfd_t *faux_pollfd, unsigned int index);
 struct pollfd *faux_pollfd_find(faux_pollfd_t *faux_pollfd, int fd);
 struct pollfd *faux_pollfd_add(faux_pollfd_t *faux_pollfd, int fd, short events);
-int faux_pollfd_del_by_fd(faux_pollfd_t *faux_pollfd, int fd);
-int faux_pollfd_del_by_index(faux_pollfd_t *faux_pollfd, unsigned int index);
+bool_t faux_pollfd_del_by_fd(faux_pollfd_t *faux_pollfd, int fd);
+bool_t faux_pollfd_del_by_index(faux_pollfd_t *faux_pollfd, unsigned int index);
 void faux_pollfd_init_iterator(faux_pollfd_t *faux_pollfd, faux_pollfd_iterator_t *iterator);
 struct pollfd *faux_pollfd_each(faux_pollfd_t *faux_pollfd, faux_pollfd_iterator_t *iterator);
 struct pollfd *faux_pollfd_each_active(faux_pollfd_t *faux_pollfd, faux_pollfd_iterator_t *iterator);

+ 16 - 10
faux/net/pollfd.c

@@ -181,24 +181,27 @@ struct pollfd *faux_pollfd_add(faux_pollfd_t *faux_pollfd, int fd, short events)
  *
  * @param [in] faux_pollfd Allocated faux_pollfd_t object.
  * @param [in] fd File descriptor to remove.
- * @return 0 - success, < 0 on error.
+ * @return BOOL_TRUE - success, BOOL_FALSE on error.
  */
-int faux_pollfd_del_by_fd(faux_pollfd_t *faux_pollfd, int fd)
+bool_t faux_pollfd_del_by_fd(faux_pollfd_t *faux_pollfd, int fd)
 {
 	int index = 0;
 
 	assert(faux_pollfd);
 	if (!faux_pollfd)
-		return -1;
+		return BOOL_FALSE;
 	assert(fd >= 0);
 	if (fd < 0)
-		return -1;
+		return BOOL_FALSE;
 
 	index = faux_vec_find(faux_pollfd->vec, &fd, 0);
 	if (index < 0) // Not found
-		return -1;
+		return BOOL_FALSE;
 
-	return faux_vec_del(faux_pollfd->vec, index);
+	if (faux_vec_del(faux_pollfd->vec, index) < 0)
+		return BOOL_FALSE;
+
+	return BOOL_TRUE;
 }
 
 
@@ -206,15 +209,18 @@ int faux_pollfd_del_by_fd(faux_pollfd_t *faux_pollfd, int fd)
  *
  * @param [in] faux_pollfd Allocated faux_pollfd_t object.
  * @param [in] index Index of item to remove.
- * @return 0 - success, < 0 on error.
+ * @return BOOL_TRUE - success, BOOL_FALSE on error.
  */
-int faux_pollfd_del_by_index(faux_pollfd_t *faux_pollfd, unsigned int index)
+bool_t faux_pollfd_del_by_index(faux_pollfd_t *faux_pollfd, unsigned int index)
 {
 	assert(faux_pollfd);
 	if (!faux_pollfd)
-		return -1;
+		return BOOL_FALSE;
+
+	if (faux_vec_del(faux_pollfd->vec, index) < 0)
+		return BOOL_FALSE;
 
-	return faux_vec_del(faux_pollfd->vec, index);
+	return BOOL_TRUE;
 }