Subversion Repositories SvarDOS

Rev

Rev 329 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
207 mateuszvis 1
/*
2
 * This file is part of the pkgnet package - the SvarDOS package manager.
3
 * Copyright (C) Mateusz Viste 2013-2021
4
 */
5
 
6
 
7
#ifndef libtcp_hdr
8
#define libtcp_hdr
9
 
10
struct net_tcpsocket {
11
  int s;       /* used by platforms with BSD-style sockets */
12
  void *sock;  /* used by other exotic things (like Watt-32) */
13
  char buffer[1];
14
};
15
 
16
/* resolves name and fills resovled addr into ip. returns 0 on success. */
17
int net_dnsresolve(char *ip, const char *name);
18
 
19
/* must be called before using libtcp. returns 0 on success, or non-zero if network subsystem is not available. */
20
int net_init(void);
21
 
22
/* initiates a connection to an IP host and returns a socket pointer (or NULL
23
 * on error) - note that connection is NOT established at this point!
24
 * use net_isconnected() to know when the connection is connected. */
25
struct net_tcpsocket *net_connect(const char *ip, unsigned short port);
26
 
27
/* checks whether or not a socket is connected. returns:
28
 *  0 = not connected,
29
 *  1 = connected
30
 * -1 = error
31
 *
32
 * if waitstate is non-zero, then net_isconnected() may release a few cpu
33
 * cycles (useful when net_isconnected() is used within a busy loop). */
34
int net_isconnected(struct net_tcpsocket *s, int waitstate);
35
 
36
/* Sends data on socket 'socket'.
37
Returns the number of bytes sent on success, and <0 otherwise. The error code can be translated into a human error message via libtcp_strerr(). */
38
int net_send(struct net_tcpsocket *socket, const char *line, long len);
39
 
40
/* Reads data from socket 'sock' and write it into buffer 'buff', until end of connection. Will fall into error if the amount of data is bigger than 'maxlen' bytes.
41
Returns the amount of data read (in bytes) on success, or a negative value otherwise. The error code can be translated into a human error message via libtcp_strerr(). */
42
int net_recv(struct net_tcpsocket *socket, char *buff, long maxlen);
43
 
44
/* Close the 'sock' socket. */
45
void net_close(struct net_tcpsocket *socket);
46
 
47
/* Close the 'sock' socket immediately (to be used when the peer is behaving wrongly) - this is much faster than net_close(). */
48
void net_abort(struct net_tcpsocket *socket);
49
 
50
/* Returns an info string about the networking engine being used */
51
const char *net_engine(void);
52
 
53
#endif