<commit_before>//
// Copyright 2016 <NAME> <<EMAIL>>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt).  A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//

#ifndef CORE_TRANSPORT_H
#define CORE_TRANSPORT_H

// Transport implementation details.  Transports must implement the
// interfaces in this file.

struct nni_tran {
	// tran_scheme is the transport scheme, such as "tcp" or "inproc".
	const char *		tran_scheme;

	// tran_ep links our endpoint-specific operations.
	const nni_tran_ep *	tran_ep;

	// tran_pipe links our pipe-specific operations.
	const nni_tran_pipe *	tran_pipe;

	// tran_init, if not NULL, is called once during library
	// initialization.
	int			(*tran_init)(void);

	// tran_fini, if not NULL, is called during library deinitialization.
	// It should release any global resources, close any open files, etc.
	void			(*tran_fini)(void);
};


// Endpoint operations are called by the socket in a protocol-independent
// fashion.  The socket makes individual calls, which are expected to block
// if appropriate (except for destroy). Endpoints are unable to call back
// into the socket, to prevent recusive entry and deadlock.
struct nni_tran_ep {
	// ep_init creates a vanilla endpoint. The value created is
	// used for the first argument for all other endpoint functions.
	int	(*ep_init)(void **, const char *, nni_sock *);

	// ep_fini frees the resources associated with the endpoint.
	// The endpoint will already have been closed.
	void	(*ep_fini)(void *);

	// ep_connect establishes a connection.  It can return errors
	// NNG_EACCESS, NNG_ECONNREFUSED, NNG_EBADADDR, NNG_ECONNFAILED,
	// NNG_ETIMEDOUT, and NNG_EPROTO.  The first argument is the
	// transport specific endpoint, and the second is the transport
	// specific pipe structure.
	int	(*ep_connect)(void *, void *);

	// ep_bind just does the bind() and listen() work,
	// reserving the address but not creating any connections.
	// It should return NNG_EADDRINUSE if the address is already
	// taken.  It can also return NNG_EBADADDR for an unsuitable
	// address, or NNG_EACCESS for permission problems.
	int	(*ep_bind)(void *);

	// ep_accept accepts an inbound connection.  The first argument
	// is the transport-specific endpoint, and the second is the
	// transport-specific pipe (which will have already been created.)
	int	(*ep_accept)(void *, void *);

	// ep_close stops the endpoint from operating altogether.  It does
	// not affect pipes that have already been created.
	void	(*ep_close)(void *);

	// ep_setopt sets an endpoint (transport-specific) option.
	int	(*ep_setopt)(void *, int, const void *, size_t);

	// ep_getopt gets an endpoint (transport-specific) option.
	int	(*ep_getopt)(void *, int, void *, size_t *);
};

// Pipe operations are entry points called by the socket. These may be called
// with socket locks held, so it is forbidden for the transport to call
// back into the socket at this point.  (Which is one reason pointers back
// to socket or even enclosing pipe state, are not provided.)
struct nni_tran_pipe {
	// p_init initializes the pipe structure, allocating the structure.
	int		(*p_init)(void **);

	// p_fini destroys the pipe.  This should clean up all local
	// resources, including closing files and freeing memory, used by
	// the pipe.  After this call returns, the system will not make
	// further calls on the same pipe.
	void		(*p_fini)(void *);

	int		(*p_aio_send)(void *, nni_aio *);
	int		(*p_aio_recv)(void *, nni_aio *);

	// p_send sends the message.  If the message cannot be received, then
	// the caller may try again with the same message (or free it).  If
	// the call succeeds, then the transport has taken ownership of the
	// message, and the caller may not use it again.  The transport will
	// have the responsibility to free the message (nng_msg_free()) when
	// it is finished with it.
	int		(*pipe_send)(void *, nni_msg *);

	// p_recv recvs the message. This is a blocking operation, and a read
	// will be performed even for cases where no data is expected.  This
	// allows the socket to detect a closed socket, by the returned error
	// NNG_ECLOSED. Note that the closed socket condition can arise as
	// either a result of a remote peer closing the connection, or a
	// synchronous call to p_close.
	int		(*pipe_recv)(void *, nng_msg **);

	// p_close closes the pipe.  Further recv or send operations should
	// return back NNG_ECLOSED.
	void		(*p_close)(void *);

	// p_peer returns the peer protocol. This may arrive in whatever
	// transport specific manner is appropriate.
	uint16_t	(*p_peer)(void *);

	// p_getopt gets an pipe (transport-specific) property.  These values
	// may not be changed once the pipe is created.
	int		(*p_getopt)(void *, int, void *, size_t *);
};

// These APIs are used by the framework internally, and not for use by
// transport implementations.
extern nni_tran *nni_tran_find(const char *);
extern void nni_tran_sys_init(void);
extern void nni_tran_sys_fini(void);

#endif // CORE_TRANSPORT_H
<commit_msg>Nuke the synchronous send/recv transport methods.<commit_after>//
// Copyright 2016 <NAME> <<EMAIL>>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt).  A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//

#ifndef CORE_TRANSPORT_H
#define CORE_TRANSPORT_H

// Transport implementation details.  Transports must implement the
// interfaces in this file.

struct nni_tran {
	// tran_scheme is the transport scheme, such as "tcp" or "inproc".
	const char *		tran_scheme;

	// tran_ep links our endpoint-specific operations.
	const nni_tran_ep *	tran_ep;

	// tran_pipe links our pipe-specific operations.
	const nni_tran_pipe *	tran_pipe;

	// tran_init, if not NULL, is called once during library
	// initialization.
	int			(*tran_init)(void);

	// tran_fini, if not NULL, is called during library deinitialization.
	// It should release any global resources, close any open files, etc.
	void			(*tran_fini)(void);
};


// Endpoint operations are called by the socket in a protocol-independent
// fashion.  The socket makes individual calls, which are expected to block
// if appropriate (except for destroy). Endpoints are unable to call back
// into the socket, to prevent recusive entry and deadlock.
struct nni_tran_ep {
	// ep_init creates a vanilla endpoint. The value created is
	// used for the first argument for all other endpoint functions.
	int	(*ep_init)(void **, const char *, nni_sock *);

	// ep_fini frees the resources associated with the endpoint.
	// The endpoint will already have been closed.
	void	(*ep_fini)(void *);

	// ep_connect establishes a connection.  It can return errors
	// NNG_EACCESS, NNG_ECONNREFUSED, NNG_EBADADDR, NNG_ECONNFAILED,
	// NNG_ETIMEDOUT, and NNG_EPROTO.  The first argument is the
	// transport specific endpoint, and the second is the transport
	// specific pipe structure.
	int	(*ep_connect)(void *, void *);

	// ep_bind just does the bind() and listen() work,
	// reserving the address but not creating any connections.
	// It should return NNG_EADDRINUSE if the address is already
	// taken.  It can also return NNG_EBADADDR for an unsuitable
	// address, or NNG_EACCESS for permission problems.
	int	(*ep_bind)(void *);

	// ep_accept accepts an inbound connection.  The first argument
	// is the transport-specific endpoint, and the second is the
	// transport-specific pipe (which will have already been created.)
	int	(*ep_accept)(void *, void *);

	// ep_close stops the endpoint from operating altogether.  It does
	// not affect pipes that have already been created.
	void	(*ep_close)(void *);

	// ep_setopt sets an endpoint (transport-specific) option.
	int	(*ep_setopt)(void *, int, const void *, size_t);

	// ep_getopt gets an endpoint (transport-specific) option.
	int	(*ep_getopt)(void *, int, void *, size_t *);
};

// Pipe operations are entry points called by the socket. These may be called
// with socket locks held, so it is forbidden for the transport to call
// back into the socket at this point.  (Which is one reason pointers back
// to socket or even enclosing pipe state, are not provided.)
struct nni_tran_pipe {
	// p_init initializes the pipe structure, allocating the structure.
	int		(*p_init)(void **);

	// p_fini destroys the pipe.  This should clean up all local
	// resources, including closing files and freeing memory, used by
	// the pipe.  After this call returns, the system will not make
	// further calls on the same pipe.
	void		(*p_fini)(void *);

	// p_aio_send queues the message for transmit.  If this fails, then
	// the caller may try again with the same message (or free it).  If
	// the call succeeds, then the transport has taken ownership of the
	// message, and the caller may not use it again.  The transport will
	// have the responsibility to free the message (nng_msg_free()) when
	// it is finished with it.
	int		(*p_aio_send)(void *, nni_aio *);

	// p_recv schedules a message receive. This will be performed even for
	// cases where no data is expected, to allow detection of a remote
	// disconnect.
	int		(*p_aio_recv)(void *, nni_aio *);

	// p_close closes the pipe.  Further recv or send operations should
	// return back NNG_ECLOSED.
	void		(*p_close)(void *);

	// p_peer returns the peer protocol. This may arrive in whatever
	// transport specific manner is appropriate.
	uint16_t	(*p_peer)(void *);

	// p_getopt gets an pipe (transport-specific) property.  These values
	// may not be changed once the pipe is created.
	int		(*p_getopt)(void *, int, void *, size_t *);
};

// These APIs are used by the framework internally, and not for use by
// transport implementations.
extern nni_tran *nni_tran_find(const char *);
extern void nni_tran_sys_init(void);
extern void nni_tran_sys_fini(void);

#endif // CORE_TRANSPORT_H

{'fraction_non_alphanumeric': 0.09080106941281314, 'fraction_numerical': 0.001188236459055352, 'mean_word_length': 3.639412034910427, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4079510', 'n_tokens_mistral': 3110, 'n_tokens_neox': 2979, 'n_words': 1301}