www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/04/13:30:59

Date: Tue, 4 Feb 1997 18:13:04 GMT
Message-Id: <199702041813.SAA11974@mailhost.sm.ic.ac.uk>
Mime-Version: 1.0
To: djgpp AT delorie DOT com
From: p DOT dixon AT ic DOT ac DOT uk (Paul Dixon)
Subject: DJ-WATTCP

I have been knocking together an FTP client interface using the dj-wattcp
port from the Lynx sources (many thanks for the work already done by others!)

I have a modified set of sources with (I think) improved support for listen
/ accept / getsockname - I have placed my sources at 

ftp://cy-40.sm.ic.ac.uk/tcplib

and with an ftp client which I am happy to share with anyone (./tcpsys/ftp.h
and ./tcpsys/ftp.c - interface listed below)

I have a bizarre problem - on my PC (P90 with a D-Link 16 bit ISA netcard) I
get tx rates of 300kB/s inbound, and 250kB/s outwards, but ONLY with
debugging output to the screen at every tcp write - if I disable these
printf statements then the tx rate for tcp writes drops by a factor of 20!

The offending code is horrible cos I have thrown lots of debugging waiting
etc in an attempt to fix but to no avail - does anyone have any good ideas ?


/* send a data file over an opened network socket */
int send_data_file( char *local, int sock )
{
    int ticks = rawclock();
    char block[1024]; int bytes, count = 0, lastmsg = 0;

    FILE *f = fopen( local, "rb" );
    if (f)
    {
	while (bytes = fread( block, 1, 1024, f ))
	{  
	    int off = 0, i = write_s( sock, block, bytes); count += i;
	    ftp_sleep(0); /* attempt to let packet driver work! */

	    if (debug_state > 1) printf( "write_s(,,%d) -> %d\n", bytes, i );
	    while (i < bytes)
	    {
		bytes -= i; off += i; ftp_sleep(3); /* wait 150 ms */
		i = write_s( sock, block+off, bytes); count += i;
		if (debug_state) printf( "write_s(,,%d) -> %d\n", bytes, i );
	    }
	}
	ticks = rawclock() - ticks;
	sprintf(block, "%s: %dkB transferred in %fs", local, count / 1024,
(double)ticks / 18.2 );
	if (debug_state) printf( "%s\n", block );
	fclose( f );   
    }
    return count;
}

/* Attempt to give up control to lower levels */
static void ftp_sleep(int ticks)
{
  int start; 
  for (start = rawclock(); rawclock() < start + ticks; )
  {
      tcp_tick(0);
      __dpmi_yield();
  }
}

-----------------------------------------------------------------------------
/* Interface of the FTP module */

/* initialise tcp or return fail, returns 0 = fail, 1 = OK */
int ftp_init(int debug, int (*progress_callback)(char *) );

/* connect to ftp port of host, returns 0 = OK or error code */
int ftp_hookup(char *hostname, int port);

/* login to ftp daemon, returns 0 = fail, 1 = OK */
int ftp_login(char *user, char *pass, char *acct);

/* returns FTP result code (usually 2 ? ) */
int ftp_close(void);

/* change directory, returns 0 = fail, 1 = OK */
int ftp_cwd(char *dir);

/* change directory '..', returns 0 = fail, 1 = OK */
int ftp_cdup(void);    

/* returns NULL = fail, else (static) pointer to dir */
char *ftp_pwd(void);

/* change local directory, returns 0 = fail, 1 = OK */
int ftp_lcd(char *path);

/* returns 0 = fail, or count of directory entries */
int ftp_list(int (*list_callback)(int type, char *name, char *date, long size));

/* put a file 'STOR', always binary mode, returns 0 = fail, 1 = OK */
int ftp_put(char *file);

/* get a file 'RETR', binary mode, returns 0 = fail, 1 = OK */
int ftp_get(char *file);

/* rename file at server, returns 0 = fail, 1 = OK */
int ftp_rename(char *oldpath, char *newpath);

/* make dir at server, returns 0 = fail, 1 = OK */
int ftp_mkdir(char *dir);

------------------------------------------------------------------------
Paul Dixon                                   Email: p DOT dixon AT ic DOT ac DOT uk
Software Engineer                              tel:   +44 (171) 725 1098
Academic Dept of Paediatrics                   fax:   +44 (171) 725 6284
St Mary's Hospital Medical School
 (a constituent college of 
                     Imperial College of Science, Technology & Medicine)
Norfolk Place, London W2 1PG, UK
------------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019