testpoll.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "testutil.h"
  17. #include "fspr_strings.h"
  18. #include "fspr_errno.h"
  19. #include "fspr_general.h"
  20. #include "fspr_lib.h"
  21. #include "fspr_network_io.h"
  22. #include "fspr_poll.h"
  23. #define SMALL_NUM_SOCKETS 3
  24. /* We can't use 64 here, because some platforms *ahem* Solaris *ahem* have
  25. * a default limit of 64 open file descriptors per process. If we use
  26. * 64, the test will fail even though the code is correct.
  27. */
  28. #define LARGE_NUM_SOCKETS 50
  29. static fspr_socket_t *s[LARGE_NUM_SOCKETS];
  30. static fspr_sockaddr_t *sa[LARGE_NUM_SOCKETS];
  31. static fspr_pollset_t *pollset;
  32. /* ###: tests surrounded by ifdef OLD_POLL_INTERFACE either need to be
  33. * converted to use the pollset interface or removed. */
  34. #ifdef OLD_POLL_INTERFACE
  35. static fspr_pollfd_t *pollarray;
  36. static fspr_pollfd_t *pollarray_large;
  37. #endif
  38. static void make_socket(fspr_socket_t **sock, fspr_sockaddr_t **sa,
  39. fspr_port_t port, fspr_pool_t *p, abts_case *tc)
  40. {
  41. fspr_status_t rv;
  42. rv = fspr_sockaddr_info_get(sa, "127.0.0.1", APR_UNSPEC, port, 0, p);
  43. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  44. rv = fspr_socket_create(sock, (*sa)->family, SOCK_DGRAM, 0, p);
  45. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  46. rv =fspr_socket_bind((*sock), (*sa));
  47. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  48. }
  49. #ifdef OLD_POLL_INTERFACE
  50. static void check_sockets(const fspr_pollfd_t *pollarray,
  51. fspr_socket_t **sockarray, int which, int pollin,
  52. abts_case *tc)
  53. {
  54. fspr_status_t rv;
  55. fspr_int16_t event;
  56. char *str;
  57. rv = fspr_poll_revents_get(&event, sockarray[which],
  58. (fspr_pollfd_t *)pollarray);
  59. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  60. if (pollin) {
  61. str = fspr_psprintf(p, "Socket %d not signalled when it should be",
  62. which);
  63. ABTS_ASSERT(tc, str, event & APR_POLLIN);
  64. } else {
  65. str = fspr_psprintf(p, "Socket %d signalled when it should not be",
  66. which);
  67. ABTS_ASSERT(tc, str, !(event & APR_POLLIN));
  68. }
  69. }
  70. #endif
  71. static void send_msg(fspr_socket_t **sockarray, fspr_sockaddr_t **sas, int which,
  72. abts_case *tc)
  73. {
  74. fspr_size_t len = 5;
  75. fspr_status_t rv;
  76. ABTS_PTR_NOTNULL(tc, sockarray[which]);
  77. rv = fspr_socket_sendto(sockarray[which], sas[which], 0, "hello", &len);
  78. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  79. ABTS_INT_EQUAL(tc, strlen("hello"), len);
  80. }
  81. static void recv_msg(fspr_socket_t **sockarray, int which, fspr_pool_t *p,
  82. abts_case *tc)
  83. {
  84. fspr_size_t buflen = 5;
  85. char *buffer = fspr_pcalloc(p, sizeof(char) * (buflen + 1));
  86. fspr_sockaddr_t *recsa;
  87. fspr_status_t rv;
  88. ABTS_PTR_NOTNULL(tc, sockarray[which]);
  89. fspr_sockaddr_info_get(&recsa, "127.0.0.1", APR_UNSPEC, 7770, 0, p);
  90. rv = fspr_socket_recvfrom(recsa, sockarray[which], 0, buffer, &buflen);
  91. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  92. ABTS_INT_EQUAL(tc, strlen("hello"), buflen);
  93. ABTS_STR_EQUAL(tc, "hello", buffer);
  94. }
  95. static void create_all_sockets(abts_case *tc, void *data)
  96. {
  97. int i;
  98. for (i = 0; i < LARGE_NUM_SOCKETS; i++){
  99. make_socket(&s[i], &sa[i], 7777 + i, p, tc);
  100. }
  101. }
  102. #ifdef OLD_POLL_INTERFACE
  103. static void setup_small_poll(abts_case *tc, void *data)
  104. {
  105. fspr_status_t rv;
  106. int i;
  107. rv = fspr_poll_setup(&pollarray, SMALL_NUM_SOCKETS, p);
  108. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  109. for (i = 0; i < SMALL_NUM_SOCKETS;i++){
  110. ABTS_INT_EQUAL(tc, 0, pollarray[i].reqevents);
  111. ABTS_INT_EQUAL(tc, 0, pollarray[i].rtnevents);
  112. rv = fspr_poll_socket_add(pollarray, s[i], APR_POLLIN);
  113. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  114. ABTS_PTR_EQUAL(tc, s[i], pollarray[i].desc.s);
  115. }
  116. }
  117. static void setup_large_poll(abts_case *tc, void *data)
  118. {
  119. fspr_status_t rv;
  120. int i;
  121. rv = fspr_poll_setup(&pollarray_large, LARGE_NUM_SOCKETS, p);
  122. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  123. for (i = 0; i < LARGE_NUM_SOCKETS;i++){
  124. ABTS_INT_EQUAL(tc, 0, pollarray_large[i].reqevents);
  125. ABTS_INT_EQUAL(tc, 0, pollarray_large[i].rtnevents);
  126. rv = fspr_poll_socket_add(pollarray_large, s[i], APR_POLLIN);
  127. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  128. ABTS_PTR_EQUAL(tc, s[i], pollarray_large[i].desc.s);
  129. }
  130. }
  131. static void nomessage(abts_case *tc, void *data)
  132. {
  133. fspr_status_t rv;
  134. int srv = SMALL_NUM_SOCKETS;
  135. rv = fspr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC);
  136. ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
  137. check_sockets(pollarray, s, 0, 0, tc);
  138. check_sockets(pollarray, s, 1, 0, tc);
  139. check_sockets(pollarray, s, 2, 0, tc);
  140. }
  141. static void send_2(abts_case *tc, void *data)
  142. {
  143. fspr_status_t rv;
  144. int srv = SMALL_NUM_SOCKETS;
  145. send_msg(s, sa, 2, tc);
  146. rv = fspr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC);
  147. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  148. check_sockets(pollarray, s, 0, 0, tc);
  149. check_sockets(pollarray, s, 1, 0, tc);
  150. check_sockets(pollarray, s, 2, 1, tc);
  151. }
  152. static void recv_2_send_1(abts_case *tc, void *data)
  153. {
  154. fspr_status_t rv;
  155. int srv = SMALL_NUM_SOCKETS;
  156. recv_msg(s, 2, p, tc);
  157. send_msg(s, sa, 1, tc);
  158. rv = fspr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC);
  159. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  160. check_sockets(pollarray, s, 0, 0, tc);
  161. check_sockets(pollarray, s, 1, 1, tc);
  162. check_sockets(pollarray, s, 2, 0, tc);
  163. }
  164. static void send_2_signaled_1(abts_case *tc, void *data)
  165. {
  166. fspr_status_t rv;
  167. int srv = SMALL_NUM_SOCKETS;
  168. send_msg(s, sa, 2, tc);
  169. rv = fspr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC);
  170. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  171. check_sockets(pollarray, s, 0, 0, tc);
  172. check_sockets(pollarray, s, 1, 1, tc);
  173. check_sockets(pollarray, s, 2, 1, tc);
  174. }
  175. static void recv_1_send_0(abts_case *tc, void *data)
  176. {
  177. fspr_status_t rv;
  178. int srv = SMALL_NUM_SOCKETS;
  179. recv_msg(s, 1, p, tc);
  180. send_msg(s, sa, 0, tc);
  181. rv = fspr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC);
  182. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  183. check_sockets(pollarray, s, 0, 1, tc);
  184. check_sockets(pollarray, s, 1, 0, tc);
  185. check_sockets(pollarray, s, 2, 1, tc);
  186. }
  187. static void clear_all_signalled(abts_case *tc, void *data)
  188. {
  189. fspr_status_t rv;
  190. int srv = SMALL_NUM_SOCKETS;
  191. recv_msg(s, 0, p, tc);
  192. recv_msg(s, 2, p, tc);
  193. rv = fspr_poll(pollarray, SMALL_NUM_SOCKETS, &srv, 2 * APR_USEC_PER_SEC);
  194. ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
  195. check_sockets(pollarray, s, 0, 0, tc);
  196. check_sockets(pollarray, s, 1, 0, tc);
  197. check_sockets(pollarray, s, 2, 0, tc);
  198. }
  199. static void send_large_pollarray(abts_case *tc, void *data)
  200. {
  201. fspr_status_t rv;
  202. int lrv = LARGE_NUM_SOCKETS;
  203. int i;
  204. send_msg(s, sa, LARGE_NUM_SOCKETS - 1, tc);
  205. rv = fspr_poll(pollarray_large, LARGE_NUM_SOCKETS, &lrv,
  206. 2 * APR_USEC_PER_SEC);
  207. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  208. for (i = 0; i < LARGE_NUM_SOCKETS; i++) {
  209. if (i == (LARGE_NUM_SOCKETS - 1)) {
  210. check_sockets(pollarray_large, s, i, 1, tc);
  211. }
  212. else {
  213. check_sockets(pollarray_large, s, i, 0, tc);
  214. }
  215. }
  216. }
  217. static void recv_large_pollarray(abts_case *tc, void *data)
  218. {
  219. fspr_status_t rv;
  220. int lrv = LARGE_NUM_SOCKETS;
  221. int i;
  222. recv_msg(s, LARGE_NUM_SOCKETS - 1, p, tc);
  223. rv = fspr_poll(pollarray_large, LARGE_NUM_SOCKETS, &lrv,
  224. 2 * APR_USEC_PER_SEC);
  225. ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
  226. for (i = 0; i < LARGE_NUM_SOCKETS; i++) {
  227. check_sockets(pollarray_large, s, i, 0, tc);
  228. }
  229. }
  230. #endif
  231. static void setup_pollset(abts_case *tc, void *data)
  232. {
  233. fspr_status_t rv;
  234. rv = fspr_pollset_create(&pollset, LARGE_NUM_SOCKETS, p, 0);
  235. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  236. }
  237. static void multi_event_pollset(abts_case *tc, void *data)
  238. {
  239. fspr_status_t rv;
  240. fspr_pollfd_t socket_pollfd;
  241. int lrv;
  242. const fspr_pollfd_t *descs = NULL;
  243. ABTS_PTR_NOTNULL(tc, s[0]);
  244. socket_pollfd.desc_type = APR_POLL_SOCKET;
  245. socket_pollfd.reqevents = APR_POLLIN | APR_POLLOUT;
  246. socket_pollfd.desc.s = s[0];
  247. socket_pollfd.client_data = s[0];
  248. rv = fspr_pollset_add(pollset, &socket_pollfd);
  249. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  250. send_msg(s, sa, 0, tc);
  251. rv = fspr_pollset_poll(pollset, 0, &lrv, &descs);
  252. ABTS_INT_EQUAL(tc, 0, APR_STATUS_IS_TIMEUP(rv));
  253. if (lrv == 1) {
  254. ABTS_PTR_EQUAL(tc, s[0], descs[0].desc.s);
  255. ABTS_INT_EQUAL(tc, APR_POLLIN | APR_POLLOUT, descs[0].rtnevents);
  256. ABTS_PTR_EQUAL(tc, s[0], descs[0].client_data);
  257. }
  258. else if (lrv == 2) {
  259. ABTS_PTR_EQUAL(tc, s[0], descs[0].desc.s);
  260. ABTS_PTR_EQUAL(tc, s[0], descs[0].client_data);
  261. ABTS_PTR_EQUAL(tc, s[0], descs[1].desc.s);
  262. ABTS_PTR_EQUAL(tc, s[0], descs[1].client_data);
  263. ABTS_ASSERT(tc, "returned events incorrect",
  264. ((descs[0].rtnevents | descs[1].rtnevents)
  265. == (APR_POLLIN | APR_POLLOUT))
  266. && descs[0].rtnevents != descs[1].rtnevents);
  267. }
  268. else {
  269. ABTS_ASSERT(tc, "either one or two events returned",
  270. lrv == 1 || lrv == 2);
  271. }
  272. recv_msg(s, 0, p, tc);
  273. rv = fspr_pollset_poll(pollset, 0, &lrv, &descs);
  274. ABTS_INT_EQUAL(tc, 0, APR_STATUS_IS_TIMEUP(rv));
  275. ABTS_INT_EQUAL(tc, 1, lrv);
  276. ABTS_PTR_EQUAL(tc, s[0], descs[0].desc.s);
  277. ABTS_INT_EQUAL(tc, APR_POLLOUT, descs[0].rtnevents);
  278. ABTS_PTR_EQUAL(tc, s[0], descs[0].client_data);
  279. rv = fspr_pollset_remove(pollset, &socket_pollfd);
  280. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  281. }
  282. static void add_sockets_pollset(abts_case *tc, void *data)
  283. {
  284. fspr_status_t rv;
  285. int i;
  286. for (i = 0; i < LARGE_NUM_SOCKETS;i++){
  287. fspr_pollfd_t socket_pollfd;
  288. ABTS_PTR_NOTNULL(tc, s[i]);
  289. socket_pollfd.desc_type = APR_POLL_SOCKET;
  290. socket_pollfd.reqevents = APR_POLLIN;
  291. socket_pollfd.desc.s = s[i];
  292. socket_pollfd.client_data = s[i];
  293. rv = fspr_pollset_add(pollset, &socket_pollfd);
  294. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  295. }
  296. }
  297. static void nomessage_pollset(abts_case *tc, void *data)
  298. {
  299. fspr_status_t rv;
  300. int lrv;
  301. const fspr_pollfd_t *descs = NULL;
  302. rv = fspr_pollset_poll(pollset, 0, &lrv, &descs);
  303. ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
  304. ABTS_INT_EQUAL(tc, 0, lrv);
  305. ABTS_PTR_EQUAL(tc, NULL, descs);
  306. }
  307. static void send0_pollset(abts_case *tc, void *data)
  308. {
  309. fspr_status_t rv;
  310. const fspr_pollfd_t *descs = NULL;
  311. int num;
  312. send_msg(s, sa, 0, tc);
  313. rv = fspr_pollset_poll(pollset, 0, &num, &descs);
  314. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  315. ABTS_INT_EQUAL(tc, 1, num);
  316. ABTS_PTR_NOTNULL(tc, descs);
  317. ABTS_PTR_EQUAL(tc, s[0], descs[0].desc.s);
  318. ABTS_PTR_EQUAL(tc, s[0], descs[0].client_data);
  319. }
  320. static void recv0_pollset(abts_case *tc, void *data)
  321. {
  322. fspr_status_t rv;
  323. int lrv;
  324. const fspr_pollfd_t *descs = NULL;
  325. recv_msg(s, 0, p, tc);
  326. rv = fspr_pollset_poll(pollset, 0, &lrv, &descs);
  327. ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
  328. ABTS_INT_EQUAL(tc, 0, lrv);
  329. ABTS_PTR_EQUAL(tc, NULL, descs);
  330. }
  331. static void send_middle_pollset(abts_case *tc, void *data)
  332. {
  333. fspr_status_t rv;
  334. const fspr_pollfd_t *descs = NULL;
  335. int num;
  336. send_msg(s, sa, 2, tc);
  337. send_msg(s, sa, 5, tc);
  338. rv = fspr_pollset_poll(pollset, 0, &num, &descs);
  339. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  340. ABTS_INT_EQUAL(tc, 2, num);
  341. ABTS_PTR_NOTNULL(tc, descs);
  342. ABTS_ASSERT(tc, "Incorrect socket in result set",
  343. ((descs[0].desc.s == s[2]) && (descs[1].desc.s == s[5])) ||
  344. ((descs[0].desc.s == s[5]) && (descs[1].desc.s == s[2])));
  345. }
  346. static void clear_middle_pollset(abts_case *tc, void *data)
  347. {
  348. fspr_status_t rv;
  349. int lrv;
  350. const fspr_pollfd_t *descs = NULL;
  351. recv_msg(s, 2, p, tc);
  352. recv_msg(s, 5, p, tc);
  353. rv = fspr_pollset_poll(pollset, 0, &lrv, &descs);
  354. ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
  355. ABTS_INT_EQUAL(tc, 0, lrv);
  356. ABTS_PTR_EQUAL(tc, NULL, descs);
  357. }
  358. static void send_last_pollset(abts_case *tc, void *data)
  359. {
  360. fspr_status_t rv;
  361. const fspr_pollfd_t *descs = NULL;
  362. int num;
  363. send_msg(s, sa, LARGE_NUM_SOCKETS - 1, tc);
  364. rv = fspr_pollset_poll(pollset, 0, &num, &descs);
  365. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  366. ABTS_INT_EQUAL(tc, 1, num);
  367. ABTS_PTR_NOTNULL(tc, descs);
  368. ABTS_PTR_EQUAL(tc, s[LARGE_NUM_SOCKETS - 1], descs[0].desc.s);
  369. ABTS_PTR_EQUAL(tc, s[LARGE_NUM_SOCKETS - 1], descs[0].client_data);
  370. }
  371. static void clear_last_pollset(abts_case *tc, void *data)
  372. {
  373. fspr_status_t rv;
  374. int lrv;
  375. const fspr_pollfd_t *descs = NULL;
  376. recv_msg(s, LARGE_NUM_SOCKETS - 1, p, tc);
  377. rv = fspr_pollset_poll(pollset, 0, &lrv, &descs);
  378. ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
  379. ABTS_INT_EQUAL(tc, 0, lrv);
  380. ABTS_PTR_EQUAL(tc, NULL, descs);
  381. }
  382. static void close_all_sockets(abts_case *tc, void *data)
  383. {
  384. fspr_status_t rv;
  385. int i;
  386. for (i = 0; i < LARGE_NUM_SOCKETS; i++){
  387. rv = fspr_socket_close(s[i]);
  388. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  389. }
  390. }
  391. static void pollset_remove(abts_case *tc, void *data)
  392. {
  393. fspr_status_t rv;
  394. fspr_pollset_t *pollset;
  395. const fspr_pollfd_t *hot_files;
  396. fspr_pollfd_t pfd;
  397. fspr_int32_t num;
  398. rv = fspr_pollset_create(&pollset, 5, p, 0);
  399. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  400. pfd.p = p;
  401. pfd.desc_type = APR_POLL_SOCKET;
  402. pfd.reqevents = APR_POLLOUT;
  403. pfd.desc.s = s[0];
  404. pfd.client_data = (void *)1;
  405. rv = fspr_pollset_add(pollset, &pfd);
  406. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  407. pfd.desc.s = s[1];
  408. pfd.client_data = (void *)2;
  409. rv = fspr_pollset_add(pollset, &pfd);
  410. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  411. pfd.desc.s = s[2];
  412. pfd.client_data = (void *)3;
  413. rv = fspr_pollset_add(pollset, &pfd);
  414. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  415. pfd.desc.s = s[3];
  416. pfd.client_data = (void *)4;
  417. rv = fspr_pollset_add(pollset, &pfd);
  418. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  419. rv = fspr_pollset_poll(pollset, 1000, &num, &hot_files);
  420. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  421. ABTS_INT_EQUAL(tc, 4, num);
  422. /* now remove the pollset element referring to desc s[1] */
  423. pfd.desc.s = s[1];
  424. pfd.client_data = (void *)999; /* not used on this call */
  425. rv = fspr_pollset_remove(pollset, &pfd);
  426. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  427. /* this time only three should match */
  428. rv = fspr_pollset_poll(pollset, 1000, &num, &hot_files);
  429. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  430. ABTS_INT_EQUAL(tc, 3, num);
  431. ABTS_PTR_EQUAL(tc, (void *)1, hot_files[0].client_data);
  432. ABTS_PTR_EQUAL(tc, s[0], hot_files[0].desc.s);
  433. ABTS_PTR_EQUAL(tc, (void *)3, hot_files[1].client_data);
  434. ABTS_PTR_EQUAL(tc, s[2], hot_files[1].desc.s);
  435. ABTS_PTR_EQUAL(tc, (void *)4, hot_files[2].client_data);
  436. ABTS_PTR_EQUAL(tc, s[3], hot_files[2].desc.s);
  437. /* now remove the pollset elements referring to desc s[2] */
  438. pfd.desc.s = s[2];
  439. pfd.client_data = (void *)999; /* not used on this call */
  440. rv = fspr_pollset_remove(pollset, &pfd);
  441. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  442. /* this time only two should match */
  443. rv = fspr_pollset_poll(pollset, 1000, &num, &hot_files);
  444. ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
  445. ABTS_INT_EQUAL(tc, 2, num);
  446. ABTS_ASSERT(tc, "Incorrect socket in result set",
  447. ((hot_files[0].desc.s == s[0]) && (hot_files[1].desc.s == s[3])) ||
  448. ((hot_files[0].desc.s == s[3]) && (hot_files[1].desc.s == s[0])));
  449. ABTS_ASSERT(tc, "Incorrect client data in result set",
  450. ((hot_files[0].client_data == (void *)1) &&
  451. (hot_files[1].client_data == (void *)4)) ||
  452. ((hot_files[0].client_data == (void *)4) &&
  453. (hot_files[1].client_data == (void *)1)));
  454. }
  455. abts_suite *testpoll(abts_suite *suite)
  456. {
  457. suite = ADD_SUITE(suite)
  458. abts_run_test(suite, create_all_sockets, NULL);
  459. #ifdef OLD_POLL_INTERFACE
  460. abts_run_test(suite, setup_small_poll, NULL);
  461. abts_run_test(suite, setup_large_poll, NULL);
  462. abts_run_test(suite, nomessage, NULL);
  463. abts_run_test(suite, send_2, NULL);
  464. abts_run_test(suite, recv_2_send_1, NULL);
  465. abts_run_test(suite, send_2_signaled_1, NULL);
  466. abts_run_test(suite, recv_1_send_0, NULL);
  467. abts_run_test(suite, clear_all_signalled, NULL);
  468. abts_run_test(suite, send_large_pollarray, NULL);
  469. abts_run_test(suite, recv_large_pollarray, NULL);
  470. #endif
  471. abts_run_test(suite, setup_pollset, NULL);
  472. abts_run_test(suite, multi_event_pollset, NULL);
  473. abts_run_test(suite, add_sockets_pollset, NULL);
  474. abts_run_test(suite, nomessage_pollset, NULL);
  475. abts_run_test(suite, send0_pollset, NULL);
  476. abts_run_test(suite, recv0_pollset, NULL);
  477. abts_run_test(suite, send_middle_pollset, NULL);
  478. abts_run_test(suite, clear_middle_pollset, NULL);
  479. abts_run_test(suite, send_last_pollset, NULL);
  480. abts_run_test(suite, clear_last_pollset, NULL);
  481. abts_run_test(suite, pollset_remove, NULL);
  482. abts_run_test(suite, close_all_sockets, NULL);
  483. return suite;
  484. }