Subversion Repositories SvarDOS

Rev

Rev 885 | Rev 1133 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 885 Rev 1132
Line 25... Line 25...
25
 * 10K = 98 KiB/s
25
 * 10K = 98 KiB/s
26
 * 16K = 96 KiB/s
26
 * 16K = 96 KiB/s
27
 * 32K = 98 KiB/s
27
 * 32K = 98 KiB/s
28
 * 60K = 98 KiB/s
28
 * 60K = 98 KiB/s
29
 */
29
 */
30
#define TCPBUFF_SIZE (16 * 1024)
-
 
31
 
-
 
32
 
30
 
33
struct net_tcpsocket {
31
struct net_tcpsocket {
34
  tcp_Socket *sock;
32
  tcp_Socket *sock;
35
  tcp_Socket _sock; /* watt32 socket */
33
  tcp_Socket _sock; /* watt32 socket */
36
  char tcpbuff[1];
34
  char tcpbuff[1];
Line 62... Line 60...
62
  _printf = dummy_printf;  /* this is to avoid watt32 printing its stuff to console */
60
  _printf = dummy_printf;  /* this is to avoid watt32 printing its stuff to console */
63
  return(sock_init());
61
  return(sock_init());
64
}
62
}
65
 
63
 
66
 
64
 
67
struct net_tcpsocket *net_connect(const char *ipstr, unsigned short port) {
65
struct net_tcpsocket *net_connect(const char *ipstr, unsigned short port, unsigned short buffsz) {
68
  struct net_tcpsocket *resultsock, *resizsock;
66
  struct net_tcpsocket *resultsock;
69
  unsigned long ipaddr;
67
  unsigned long ipaddr;
70
 
68
 
71
  /* convert ip to value */
69
  /* convert ip to value */
72
  ipaddr = _inet_addr(ipstr);
70
  ipaddr = _inet_addr(ipstr);
73
  if (ipaddr == 0) return(NULL);
71
  if (ipaddr == 0) return(NULL);
74
 
72
 
-
 
73
  /* ignore buffsz smaller than 2K (wattcp already has a 2K buffer) */
-
 
74
  if (buffsz <= 2048) buffsz = 0;
-
 
75
 
75
  resultsock = calloc(sizeof(struct net_tcpsocket), 1);
76
  resultsock = calloc(sizeof(struct net_tcpsocket) + buffsz, 1);
76
  if (resultsock == NULL) return(NULL);
77
  if (resultsock == NULL) return(NULL);
77
  resultsock->sock = &(resultsock->_sock);
78
  resultsock->sock = &(resultsock->_sock);
78
 
79
 
79
  if (!tcp_open(resultsock->sock, 0, ipaddr, port, NULL)) {
80
  if (!tcp_open(resultsock->sock, 0, ipaddr, port, NULL)) {
80
    sock_abort(resultsock->sock);
81
    sock_abort(resultsock->sock);
81
    free(resultsock);
82
    free(resultsock);
82
    return(NULL);
83
    return(NULL);
83
  }
84
  }
84
 
85
 
85
  /* set user-managed buffer if possible (watt32's default is only 2K)
86
  /* set user-managed buffer if requested (watt32's default is only 2K)
86
   * this must be set AFTER tcp_open(), since the latter rewrites the tcp
87
   * this must be set AFTER tcp_open(), since the latter rewrites the tcp
87
   * rx buffer */
88
   * rx buffer */
88
  resizsock = realloc(resultsock, sizeof(struct net_tcpsocket) + TCPBUFF_SIZE);
-
 
89
  if (resizsock != NULL) {
-
 
90
    resultsock = resizsock;
-
 
91
    sock_setbuf(resultsock->sock, resultsock->tcpbuff, TCPBUFF_SIZE);
89
  if (buffsz > 0) sock_setbuf(resultsock->sock, resultsock->tcpbuff, buffsz);
92
  }
-
 
93
 
90
 
94
  return(resultsock);
91
  return(resultsock);
95
}
92
}
96
 
93
 
97
 
94