PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/io/grovel.lisp

https://github.com/sheafferusa/core-server
Lisp | 210 lines | 129 code | 31 blank | 50 comment | 0 complexity | fcd139df4144a56dcb7194703f8c1d1f MD5 | raw file
Possible License(s): GPL-3.0
  1. (in-package :tr.gen.core.ffi)
  2. (ctype retval "int")
  3. ;;;-----------------------------------------------------------------------------
  4. ;;; GETPROTOBYNAME, GETHOSTBYNAME TYPE DEFINITIONS
  5. ;;;-----------------------------------------------------------------------------
  6. (include "netdb.h")
  7. (cstruct protoent "struct protoent"
  8. (name "p_name" :type :string)
  9. (aliases "p_aliases" :type :pointer)
  10. (proto "p_proto" :type :int))
  11. (cstruct hostent "struct hostent"
  12. (name "h_name" :type :string)
  13. (aliases "h_aliases" :type :pointer)
  14. (type "h_addrtype" :type :int)
  15. (len "h_length" :type :int)
  16. (list "h_addr_list" :type :pointer))
  17. (include "sys/socket.h")
  18. (constant (af-inet "AF_INET" "PF_INET")
  19. :documentation "IPv4 Protocol family")
  20. (constant (af-unspec "AF_UNSPEC"))
  21. ;; possible values for "ai-flags"
  22. (constant (flag-ai-passive "AI_PASSIVE"))
  23. (constant (flag-ai-canonname "AI_CANONNAME"))
  24. (constant (flag-ai-numerichost "AI_NUMERICHOST"))
  25. (constant (flag-ai-v4mapped "AI_V4MAPPED"))
  26. (constant (flag-ai-all "AI_ALL"))
  27. (constant (flag-ai-addrconfig "AI_ADDRCONFIG"))
  28. (constant (flag-ai-idn "AI_IDN"))
  29. (constant (flag-ai-canonidn "AI_CANONIDN"))
  30. ;; +----------------------------------------------------------------------------
  31. ;; |IPV4 SOCKET ADDRESS
  32. ;; +----------------------------------------------------------------------------
  33. (include "sys/socket.h")
  34. (ctype socklen "socklen_t")
  35. (ctype sa-family "sa_family_t")
  36. ;;; socket() - socket address family
  37. (constant (af-inet "AF_INET" "PF_INET") :documentation "IPv4 Protocol family")
  38. (constant (af-local "AF_UNIX" "AF_LOCAL" "PF_UNIX" "PF_LOCAL")
  39. :documentation "File domain sockets")
  40. ;;; socket() - socket type
  41. (constant (sock-stream "SOCK_STREAM") :documentation "TCP")
  42. (constant (sock-dgram "SOCK_DGRAM") :documentation "UDP")
  43. ;;; socket() - socket protocols
  44. (constant (ipproto-tcp "IPPROTO_TCP"))
  45. (constant (ipproto-udp "IPPROTO_UDP"))
  46. (cstruct sockaddr "struct sockaddr"
  47. (family "sa_family" :type sa-family)
  48. (sa-data "sa_data" :type :char :count 14))
  49. ;; GETNAMEINFO, GETADDRINFO
  50. (include "sys/types.h" "sys/socket.h" "netdb.h")
  51. (ctype size-t "size_t")
  52. (ctype ssize-t "ssize_t")
  53. (include "sys/sendfile.h")
  54. (ctype off-t "off_t")
  55. (constant (ni-numerichost "NI_NUMERICHOST"))
  56. (constant (ni-numericserv "NI_NUMERICSERV"))
  57. (constant (ni-maxhost "NI_MAXHOST"))
  58. (constant (ni-maxserv "NI_MAXSERV"))
  59. ;; struct addrinfo {
  60. ;; int ai_flags;
  61. ;; int ai_family;
  62. ;; int ai_socktype;
  63. ;; int ai_protocol;
  64. ;; size_t ai_addrlen;
  65. ;; struct sockaddr *ai_addr;
  66. ;; char *ai_canonname;
  67. ;; struct addrinfo *ai_next;
  68. ;; };
  69. (cstruct addrinfo "struct addrinfo"
  70. (ai-flags "ai_flags" :type :int)
  71. (ai-family "ai_family" :type :int)
  72. (ai-socktype "ai_socktype" :type :int)
  73. (ai-protocol "ai_protocol" :type :int)
  74. (ai-addrlen "ai_addrlen" :type size-t)
  75. (ai-addr "ai_addr" :type :pointer)
  76. (ai-canonname "ai_canonname" :type :pointer)
  77. (ai-next "ai_next" :type :pointer))
  78. (cstruct linger "struct linger"
  79. (l-onoff "l_onoff" :type :int)
  80. (l-linger "l_linger" :type :int))
  81. ;; +----------------------------------------------------------------------------
  82. ;; |SOCKET ADDRESS
  83. ;; +----------------------------------------------------------------------------
  84. (include "netinet/in.h")
  85. (ctype in-port "in_port_t")
  86. (ctype in-addr "in_addr_t")
  87. (cstruct sockaddr-in "struct sockaddr_in"
  88. "An IPv4 socket address."
  89. (family "sin_family" :type sa-family)
  90. (port "sin_port" :type in-port)
  91. (addr "sin_addr" :type in-addr))
  92. (cstruct in-addr-struct "struct in_addr"
  93. (addr "s_addr" :type :uint32))
  94. (include "netinet/tcp.h")
  95. (progn
  96. (constant (tcp-nodelay "TCP_NODELAY")))
  97. ;; +----------------------------------------------------------------------------
  98. ;; |SET/GETSOCKOPT
  99. ;; +----------------------------------------------------------------------------
  100. (progn
  101. (constant (sol-socket "SOL_SOCKET"))
  102. (constant (so-debug "SO_DEBUG"))
  103. (constant (so-reuseaddr "SO_REUSEADDR"))
  104. (constant (so-type "SO_TYPE"))
  105. (constant (so-error "SO_ERROR"))
  106. (constant (so-keepalive "SO_KEEPALIVE"))
  107. (constant (so-rcvtimeo "SO_RCVTIMEO"))
  108. (constant (so-sndtimeo "SO_SNDTIMEO"))
  109. (constant (so-linger "SO_LINGER")))
  110. ;; +----------------------------------------------------------------------------
  111. ;; |SEND/RECV FLAGS
  112. ;; +----------------------------------------------------------------------------
  113. (progn
  114. (constant (msg-dontwait "MSG_DONTWAIT")))
  115. ;; +----------------------------------------------------------------------------
  116. ;; |FCNTL
  117. ;; +----------------------------------------------------------------------------
  118. (include "fcntl.h")
  119. ;; FCNTL FLAGS
  120. (progn
  121. (constant (rdonly "O_RDONLY"))
  122. (constant (wdonly "O_WRONLY"))
  123. (constant (nonblock "O_NONBLOCK")))
  124. ;; FCNTL COMMANDS
  125. (progn
  126. (constant (getfd "F_GETFD"))
  127. (constant (setfd "F_SETFD"))
  128. (constant (getfl "F_GETFL"))
  129. (constant (setfl "F_SETFL"))
  130. (constant (setown "F_SETOWN"))
  131. (constant (getown "F_GETOWN"))
  132. (constant (setsig "F_SETSIG"))
  133. (constant (getsig "F_GETSIG")))
  134. ;; +----------------------------------------------------------------------------
  135. ;; | TIME
  136. ;; +----------------------------------------------------------------------------
  137. (include "time.h")
  138. (ctype time_t "time_t")
  139. (ctype suseconds "suseconds_t")
  140. (cstruct timespec "struct timespec"
  141. "UNIX time specification in seconds and nanoseconds."
  142. (sec "tv_sec" :type time_t)
  143. (nsec "tv_nsec" :type :long))
  144. ;;;-----------------------------------------------------------------------------
  145. ;;; EPOLL TYPE DEFINITIONS
  146. ;;;-----------------------------------------------------------------------------
  147. (include "sys/epoll.h" "sys/ioctl.h")
  148. (ctype uint32-t "uint32_t")
  149. (progn
  150. ;; (ctype sigset-t "sigset_t") ;; broken
  151. (cunion epoll-data "epoll_data_t"
  152. (ptr "ptr" :type :pointer)
  153. (fd "fd" :type :int)
  154. (u32 "u32" :type :uint32)
  155. (u64 "u64" :type :uint64))
  156. (cstruct epoll-event "struct epoll_event"
  157. (events "events" :type uint32-t)
  158. (data "data" :type epoll-data))
  159. ;;---------------------------------------------------------------------------
  160. ;; EPOLL EVENTS
  161. ;;---------------------------------------------------------------------------
  162. (constant (epollin "EPOLLIN"))
  163. (constant (epollrdnorm "EPOLLRDNORM"))
  164. (constant (epollrdband "EPOLLRDBAND"))
  165. (constant (epollpri "EPOLLPRI"))
  166. (constant (epollout "EPOLLOUT"))
  167. (constant (epollwrnorm "EPOLLWRNORM"))
  168. (constant (epollwrband "EPOLLWRBAND"))
  169. (constant (epollerr "EPOLLERR"))
  170. (constant (epollhup "EPOLLHUP"))
  171. (constant (epollmsg "EPOLLMSG"))
  172. ;;--------------------------------------------------------------------------
  173. ;; EPOLL OPERATIONS FOR EPOLL_CTL()
  174. ;;--------------------------------------------------------------------------
  175. (constant (epoll-ctl-add "EPOLL_CTL_ADD"))
  176. (constant (epoll-ctl-del "EPOLL_CTL_DEL"))
  177. (constant (epoll-ctl-mod "EPOLL_CTL_MOD")))
  178. ;;(include "uuid/uuid.h")
  179. ;;(ctype uuid-t "uuid_t")