home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
MISC
/
mtp.shar
/
mtpcommon.c
< prev
next >
Wrap
C/C++ Source or Header
|
2009-11-06
|
2KB
|
81 lines
/* mtpcommon.c, Version 1.1, Created 2/9/90 */
/* Dr Alan M. McIvor, BP Sunbury Research Centre */
#include <stdio.h>
#include "mtp.h"
/* These first two functions are for block I/O. Flooding the buffer
such as with
for (i = os9modhead._msize, ptr = module; i > 0; i-=j, ptr+=j)
if ((j = write(s, ptr, i)) == -1)
{
fprintf(stderr, "put_module: Error on socket I/O\n");
return(-1);
}
memory = module_memory;
j = 0;
i = module_size;
while (i > 0)
{
if ((j = read(ns, memory, i)) == -1)
shutdown_exit(ns, _errmsg(errno, "Error on socket I/O - "));
i -= j;
memory += j;
}
seems to upset the OS-9 system. Sometimes the module ends up with an
invalid CRC, which can only happen if at least one byte is screwed up
which should be impossible. Sometimes the OS-9 system crashes and won't
reboot properly unless it is powered down - something in the Ethernet
control registers must get screwed up.
*/
/* Assume the block size is always read */
int read_block(s, pbuf, bsize)
int s; /* socket descriptor */
char *pbuf; /* ptr to data buffer */
int bsize; /* data size in bytes */
{
/* read data from socket, return bsize if no error, -1 if error */
int no_to_read;
int no_read;
no_to_read = bsize;
while (no_to_read > 0)
{
if ((no_read = read(s, pbuf, no_to_read)) == -1)
return(-1);
pbuf += no_read;
no_to_read -= no_read;
}
return(bsize);
}
int write_block(s, pbuf, bsize)
int s; /* socket descriptor */
char *pbuf; /* ptr to data buffer */
int bsize; /* data size in bytes */
{
/* write data into socket, return bsize if no error, -1 if error */
int no_to_write;
int no_written;
no_to_write = bsize;
while (no_to_write > 0)
{
if ((no_written = write(s, pbuf, no_to_write)) == -1)
return(-1);
pbuf += no_written;
no_to_write -= no_written;
}
return(bsize);
}