talloc: use the system pytalloc-util for python3 as well
[sfrench/samba-autobuild/.git] / lib / tsocket / tsocket.h
index a008fd8232f1d6779d1a472fe0fb421fd9ac0dab..f52b7466dfb069cf662a7310122c372a0a52996e 100644 (file)
@@ -83,7 +83,7 @@ struct iovec;
  */
 
 /**
- * @brief Get a string representaion of the endpoint.
+ * @brief Get a string representation of the endpoint.
  *
  * This function creates a string representation of the endpoint for debugging.
  * The output will look as followed:
@@ -575,6 +575,16 @@ uint16_t tsocket_address_inet_port(const struct tsocket_address *addr);
 int tsocket_address_inet_set_port(struct tsocket_address *addr,
                                  uint16_t port);
 
+/**
+ * @brief Find out if the tsocket_address represents an unix domain endpoint.
+ *
+ * @param[in]  addr     The tsocket_address pointer
+ *
+ * @return              true if addr represents an unix domain endpoint,
+ *                      otherwise false.
+ */
+bool tsocket_address_is_unix(const struct tsocket_address *addr);
+
 #ifdef DOXYGEN
 /**
  * @brief Create a tsocket_address for a unix domain endpoint addresses.
@@ -586,6 +596,8 @@ int tsocket_address_inet_set_port(struct tsocket_address *addr,
  * @param[in]  _addr    The tsocket_address pointer to store the information.
  *
  * @return              0 on success, -1 on error with errno set.
+ *
+ * @see tsocket_address_is_unix()
  */
 int tsocket_address_unix_from_path(TALLOC_CTX *mem_ctx,
                                   const char *path,
@@ -615,6 +627,69 @@ int _tsocket_address_unix_from_path(TALLOC_CTX *mem_ctx,
 char *tsocket_address_unix_path(const struct tsocket_address *addr,
                                TALLOC_CTX *mem_ctx);
 
+#ifdef DOXYGEN
+/**
+ * @brief Wrap an existing file descriptors into the tdgram abstraction.
+ *
+ * You can use this function to wrap an existing file descriptors into the
+ * tdgram abstraction. After that you're not able to use this file descriptor
+ * for anything else. The file descriptor will be closed when the stream gets
+ * freed. If you still want to use the fd you have have to create a duplicate.
+ *
+ * @param[in]  mem_ctx  The talloc memory context to use.
+ *
+ * @param[in]  fd       The non blocking fd to use!
+ *
+ * @param[out] dgram    A pointer to store an allocated tdgram_context.
+ *
+ * @return              0 on success, -1 on error.
+ *
+ * Example:
+ * @code
+ *   fd2 = dup(fd);
+ *   rc = tdgram_bsd_existing_socket(mem_ctx, fd2, &tdgram);
+ *   if (rc < 0) {
+ *     return;
+ *   }
+ * @endcode
+ *
+ * @warning This is an internal function. You should read the code to fully
+ *          understand it if you plan to use it.
+ */
+int tdgram_bsd_existing_socket(TALLOC_CTX *mem_ctx,
+                              int fd,
+                              struct tdgram_context **dgram);
+#else
+int _tdgram_bsd_existing_socket(TALLOC_CTX *mem_ctx,
+                               int fd,
+                               struct tdgram_context **_dgram,
+                               const char *location);
+#define tdgram_bsd_existing_socket(mem_ctx, fd, dgram) \
+       _tdgram_bsd_existing_socket(mem_ctx, fd, dgram, \
+                                   __location__)
+#endif
+
+/**
+ * @brief Request a syscall optimization for tdgram_recvfrom_send()
+ *
+ * This function is only used to reduce the amount of syscalls and
+ * optimize performance. You should only use this if you know
+ * what you're doing.
+ *
+ * The optimization is off by default.
+ *
+ * @param[in]  dgram    The tdgram_context of a bsd socket, if this
+ *                      not a bsd socket the function does nothing.
+ *
+ * @param[in]  on       The boolean value to turn the optimization on and off.
+ *
+ * @return              The old boolean value.
+ *
+ * @see tdgram_recvfrom_send()
+ */
+bool tdgram_bsd_optimize_recvfrom(struct tdgram_context *dgram,
+                                 bool on);
+
 #ifdef DOXYGEN
 /**
  * @brief Create a tdgram_context for a ipv4 or ipv6 UDP communication.
@@ -630,6 +705,8 @@ char *tsocket_address_unix_path(const struct tsocket_address *addr,
  *                      communication. The function will allocate the memory.
  *
  * @return              0 on success, -1 on error with errno set.
+ *
+ * @see tdgram_inet_udp_broadcast_socket()
  */
 int tdgram_inet_udp_socket(const struct tsocket_address *local,
                            const struct tsocket_address *remote,
@@ -645,6 +722,33 @@ int _tdgram_inet_udp_socket(const struct tsocket_address *local,
        _tdgram_inet_udp_socket(local, remote, mem_ctx, dgram, __location__)
 #endif
 
+#ifdef DOXYGEN
+/**
+ * @brief Create a tdgram_context for a ipv4 UDP broadcast (and unicast) communication.
+ *
+ * @param[in]  local    An 'inet' (ipv4 only) tsocket_address for the local endpoint.
+ *
+ * @param[in]  mem_ctx  The talloc memory context to use.
+ *
+ * @param[in]  dgram    The tdgram_context pointer to setup the udp
+ *                      communication. The function will allocate the memory.
+ *
+ * @return              0 on success, -1 on error with errno set.
+ *
+ * @see tdgram_inet_udp_socket()
+ */
+int tdgram_inet_udp_broadcast_socket(const struct tsocket_address *local,
+                                    TALLOC_CTX *mem_ctx,
+                                    struct tdgram_context **dgram);
+#else
+int _tdgram_inet_udp_broadcast_socket(const struct tsocket_address *local,
+                                     TALLOC_CTX *mem_ctx,
+                                     struct tdgram_context **dgram,
+                                     const char *location);
+#define tdgram_inet_udp_broadcast_socket(local, mem_ctx, dgram) \
+       _tdgram_inet_udp_broadcast_socket(local, mem_ctx, dgram, __location__)
+#endif
+
 #ifdef DOXYGEN
 /**
  * @brief Create a tdgram_context for unix domain datagram communication.
@@ -676,6 +780,27 @@ int _tdgram_unix_socket(const struct tsocket_address *local,
        _tdgram_unix_socket(local, remote, mem_ctx, dgram, __location__)
 #endif
 
+/**
+ * @brief Request a syscall optimization for tstream_readv_send()
+ *
+ * This function is only used to reduce the amount of syscalls and
+ * optimize performance. You should only use this if you know
+ * what you're doing.
+ *
+ * The optimization is off by default.
+ *
+ * @param[in]  stream   The tstream_context of a bsd socket, if this
+ *                      not a bsd socket the function does nothing.
+ *
+ * @param[in]  on       The boolean value to turn the optimization on and off.
+ *
+ * @return              The old boolean value.
+ *
+ * @see tstream_readv_send()
+ */
+bool tstream_bsd_optimize_readv(struct tstream_context *stream,
+                               bool on);
+
 /**
  * @brief Connect async to a TCP endpoint and create a tstream_context for the
  * stream based communication.
@@ -712,23 +837,28 @@ struct tevent_req *tstream_inet_tcp_connect_send(TALLOC_CTX *mem_ctx,
  *
  * @param[in]  mem_ctx  The talloc memory context to use.
  *
- * @param[in]  stream   A tstream_context pointer to setup the tcp communication
+ * @param[out] stream   A tstream_context pointer to setup the tcp communication
  *                      on. This function will allocate the memory.
  *
+ * @param[out] local    The real 'inet' tsocket_address of the local endpoint.
+ *                      This parameter is optional and can be NULL.
+ *
  * @return              0 on success, -1 on error with perrno set.
  */
 int tstream_inet_tcp_connect_recv(struct tevent_req *req,
                                  int *perrno,
                                  TALLOC_CTX *mem_ctx,
-                                 struct tstream_context **stream);
+                                 struct tstream_context **stream,
+                                 struct tsocket_address **local)
 #else
 int _tstream_inet_tcp_connect_recv(struct tevent_req *req,
                                   int *perrno,
                                   TALLOC_CTX *mem_ctx,
                                   struct tstream_context **stream,
+                                  struct tsocket_address **local,
                                   const char *location);
-#define tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream) \
-       _tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream, \
+#define tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream, local) \
+       _tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream, local, \
                                       __location__)
 #endif
 
@@ -838,12 +968,12 @@ struct sockaddr;
  * @return              0 on success, -1 on error with errno set.
  */
 int tsocket_address_bsd_from_sockaddr(TALLOC_CTX *mem_ctx,
-                                     struct sockaddr *sa,
+                                     const struct sockaddr *sa,
                                      size_t sa_socklen,
                                      struct tsocket_address **addr);
 #else
 int _tsocket_address_bsd_from_sockaddr(TALLOC_CTX *mem_ctx,
-                                      struct sockaddr *sa,
+                                      const struct sockaddr *sa,
                                       size_t sa_socklen,
                                       struct tsocket_address **_addr,
                                       const char *location);
@@ -890,16 +1020,26 @@ ssize_t tsocket_address_bsd_sockaddr(const struct tsocket_address *addr,
  * for anything else. The file descriptor will be closed when the stream gets
  * freed. If you still want to use the fd you have have to create a duplicate.
  *
- * @param[in]  mem_ctx      The talloc memory context to use.
+ * @param[in]  mem_ctx  The talloc memory context to use.
  *
- * @param[in]  fd           The non blocking fd to use!
+ * @param[in]  fd       The non blocking fd to use!
  *
- * @param[in]  stream       The filed tstream_context you allocated before.
+ * @param[out] stream   A pointer to store an allocated tstream_context.
  *
- * @return              0 on success, -1 on error with errno set.
+ * @return              0 on success, -1 on error.
+ *
+ * Example:
+ * @code
+ *   fd2 = dup(fd);
+ *   rc = tstream_bsd_existing_socket(mem_ctx, fd2, &tstream);
+ *   if (rc < 0) {
+ *     stream_terminate_connection(conn, "named_pipe_accept: out of memory");
+ *     return;
+ *   }
+ * @endcode
  *
- * @warning You should read the tsocket_bsd.c code and unterstand it in order
- * use this function.
+ * @warning This is an internal function. You should read the code to fully
+ *          understand it if you plan to use it.
  */
 int tstream_bsd_existing_socket(TALLOC_CTX *mem_ctx,
                                int fd,