usock_win.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Copyright (c) 2013 Martin Sustrik All rights reserved.
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"),
  5. to deal in the Software without restriction, including without limitation
  6. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  7. and/or sell copies of the Software, and to permit persons to whom
  8. the Software is furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included
  10. in all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  14. THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  16. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  17. IN THE SOFTWARE.
  18. */
  19. #include "fsm.h"
  20. #include "worker.h"
  21. #include "../utils/win.h"
  22. struct nn_usock {
  23. /* The state machine. */
  24. struct nn_fsm fsm;
  25. int state;
  26. union {
  27. /* The actual underlying socket. Can be used as a HANDLE too. */
  28. SOCKET s;
  29. /* Named pipe handle. Cannot be used as a SOCKET. */
  30. HANDLE p;
  31. };
  32. /* For NamedPipes, closing an accepted pipe differs from other pipes.
  33. If the NamedPipe was accepted, this member is set to 1. 0 otherwise. */
  34. int isaccepted;
  35. /* Asynchronous operations being executed on the socket. */
  36. struct nn_worker_op in;
  37. struct nn_worker_op out;
  38. /* When accepting new socket, they have to be created with same
  39. type as the listening socket. Thus, in listening socket we
  40. have to store its exact type. */
  41. int domain;
  42. int type;
  43. int protocol;
  44. /* Events raised by the usock. */
  45. struct nn_fsm_event event_established;
  46. struct nn_fsm_event event_sent;
  47. struct nn_fsm_event event_received;
  48. struct nn_fsm_event event_error;
  49. /* In ACCEPTING state points to the socket being accepted.
  50. In BEING_ACCEPTED state points to the listener socket. */
  51. struct nn_usock *asock;
  52. /* Buffer allocated for output of AcceptEx function. If accepting is not
  53. done on this socket, the field is set to NULL. */
  54. void *ainfo;
  55. /* For NamedPipes, we store the address inside the socket. */
  56. struct sockaddr_un pipename;
  57. /* For now we allocate a new buffer for each write to a named pipe. */
  58. void *pipesendbuf;
  59. /* Pointer to the security attribute structure */
  60. SECURITY_ATTRIBUTES *sec_attr;
  61. /* Out Buffer and In Buffer size */
  62. int outbuffersz;
  63. int inbuffersz;
  64. /* Errno remembered in NN_USOCK_ERROR state */
  65. int errnum;
  66. };