Subversion Repositories SvarDOS

Rev

Rev 333 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 333 Rev 335
Line 12... Line 12...
12
#include <tcp.h>
12
#include <tcp.h>
13
 
13
 
14
#include "net.h" /* include self for control */
14
#include "net.h" /* include self for control */
15
 
15
 
16
 
16
 
-
 
17
/* if there is enough memory, net_connect() will try setting up a tcp window
-
 
18
 * larger than the WATT32's default of only 2K
-
 
19
 * on my system's DOSEMU install the relation between tcp buffer and download
-
 
20
 * speed were measured as follows (this is on a 4 Mbps ADSL link):
-
 
21
 *  2K = 20 KiB/s
-
 
22
 *  4K = 51 KiB/s
-
 
23
 *  8K = 67 KiB/s
-
 
24
 *  9K = 98 KiB/s
-
 
25
 * 10K = 98 KiB/s
-
 
26
 * 16K = 96 KiB/s
-
 
27
 * 32K = 98 KiB/s
-
 
28
 * 60K = 98 KiB/s
-
 
29
 */
-
 
30
#define TCPBUFF_SIZE (16 * 1024)
-
 
31
 
-
 
32
 
17
struct net_tcpsocket {
33
struct net_tcpsocket {
18
  tcp_Socket *sock;
34
  tcp_Socket *sock;
19
  tcp_Socket _sock; /* watt32 socket */
35
  tcp_Socket _sock; /* watt32 socket */
-
 
36
  char tcpbuff[1];
20
};
37
};
21
 
38
 
22
 
39
 
23
int net_dnsresolve(char *ip, const char *name) {
40
int net_dnsresolve(char *ip, const char *name) {
24
  unsigned long ipnum;
41
  unsigned long ipnum;
Line 44... Line 61...
44
  return(sock_init());
61
  return(sock_init());
45
}
62
}
46
 
63
 
47
 
64
 
48
struct net_tcpsocket *net_connect(const char *ipstr, unsigned short port) {
65
struct net_tcpsocket *net_connect(const char *ipstr, unsigned short port) {
49
  struct net_tcpsocket *resultsock;
66
  struct net_tcpsocket *resultsock, *resizsock;
50
  unsigned long ipaddr;
67
  unsigned long ipaddr;
51
 
68
 
52
  /* convert ip to value */
69
  /* convert ip to value */
53
  ipaddr = _inet_addr(ipstr);
70
  ipaddr = _inet_addr(ipstr);
54
  if (ipaddr == 0) return(NULL);
71
  if (ipaddr == 0) return(NULL);
55
 
72
 
56
  resultsock = calloc(sizeof(struct net_tcpsocket), 1);
73
  resultsock = calloc(sizeof(struct net_tcpsocket), 1);
57
  if (resultsock == NULL) return(NULL);
74
  if (resultsock == NULL) return(NULL);
58
  resultsock->sock = &(resultsock->_sock);
75
  resultsock->sock = &(resultsock->_sock);
59
 
76
 
60
  /* explicitely set user-managed buffer to none (watt32 will use its own internal buffer) */
-
 
61
  sock_setbuf(resultsock->sock, NULL, 0);
-
 
62
 
-
 
63
  if (!tcp_open(resultsock->sock, 0, ipaddr, port, NULL)) {
77
  if (!tcp_open(resultsock->sock, 0, ipaddr, port, NULL)) {
64
    sock_abort(resultsock->sock);
78
    sock_abort(resultsock->sock);
65
    free(resultsock);
79
    free(resultsock);
66
    return(NULL);
80
    return(NULL);
67
  }
81
  }
68
 
82
 
-
 
83
  /* set user-managed buffer if possible (watt32's default is only 2K)
-
 
84
   * this must be set AFTER tcp_open(), since the latter rewrites the tcp
-
 
85
   * rx buffer */
-
 
86
  resizsock = realloc(resultsock, sizeof(struct net_tcpsocket) + TCPBUFF_SIZE);
-
 
87
  if (resizsock != NULL) {
-
 
88
    resultsock = resizsock;
-
 
89
    sock_setbuf(resultsock->sock, resultsock->tcpbuff, TCPBUFF_SIZE);
-
 
90
  }
-
 
91
 
69
  return(resultsock);
92
  return(resultsock);
70
}
93
}
71
 
94
 
72
 
95
 
73
int net_isconnected(struct net_tcpsocket *s) {
96
int net_isconnected(struct net_tcpsocket *s) {