/*
 * Created by hongbo.he@lnxall.com
 *
 * 2025/09/01
 */
#ifndef LNXUTILS_NET_H
#define LNXUTILS_NET_H

#include <unistd.h>
#include <stdint.h>

/*
 * create a socket fd of tcp non-block mode
 *
 * RETURN VALUE
 *	if success, return fd
 *	while create failed, return -1 and set the errno
 *
 */
int lnxutil_tcp_socket_create(void);

/*
 * connect to host(server) with tcp
 *
 * RETURN VALUE
 *	if success, return 1
 *	while not success immidiately, return 0 and set the errno
 *	or connect failed, return -1
 *
 * ERRORS
 *	EINPROGRESS
 *	 The socket is nonblocking and the connection cannot be completed immediately
 *	EALREADY
 *	 The socket is nonblocking and a previous connection attempt has not yet been completed
 *
 */
int lnxutil_tcp_host_connect(int fd, uint8_t srv_ip[4], uint16_t port);

/*
 * send data with opened sockfd
 *
 * RETURN VALUE
 *	if success, return length you sent
 *	when send failed, return -1 and set the errno
 *
 */
ssize_t lnxutil_socket_send(int fd, const char *buff, size_t len);


#endif
