mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
lib/tsocket: add tdgram_bsd_existing_socket() helper function
This is similar to tstream_bsd_existing_socket(). Both help to migrate strange code path to using the tstream or tdgram abstractions. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
44584f8107
commit
3a8b7b0518
@ -627,6 +627,48 @@ 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()
|
||||
*
|
||||
|
@ -1388,6 +1388,30 @@ static int tdgram_bsd_dgram_socket(const struct tsocket_address *local,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _tdgram_bsd_existing_socket(TALLOC_CTX *mem_ctx,
|
||||
int fd,
|
||||
struct tdgram_context **_dgram,
|
||||
const char *location)
|
||||
{
|
||||
struct tdgram_context *dgram;
|
||||
struct tdgram_bsd *bsds;
|
||||
|
||||
dgram = tdgram_context_create(mem_ctx,
|
||||
&tdgram_bsd_ops,
|
||||
&bsds,
|
||||
struct tdgram_bsd,
|
||||
location);
|
||||
if (!dgram) {
|
||||
return -1;
|
||||
}
|
||||
ZERO_STRUCTP(bsds);
|
||||
bsds->fd = fd;
|
||||
talloc_set_destructor(bsds, tdgram_bsd_destructor);
|
||||
|
||||
*_dgram = dgram;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _tdgram_inet_udp_socket(const struct tsocket_address *local,
|
||||
const struct tsocket_address *remote,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
|
Loading…
Reference in New Issue
Block a user