error checking

master
andrew 2009-02-18 12:41:04 -06:00
parent 63d6decaad
commit 1c942c3f05
2 changed files with 16 additions and 3 deletions

View File

@ -103,10 +103,22 @@ void send_file(int skt, const char *filename)
/* send number of segments and file size to the other size cmd:arg style */
sprintf(msg, "%d:%d", segments, fsize);
/* do not expect a response, only data after this */
send(skt, msg, strlen(msg), 0);
if(send(skt, msg, strlen(msg), 0) < 0)
{
sprintf(errmsg, "Failed to send the number of segments: %s", strerror(errno));
error(errmsg);
return;
}
/* now read in the file, MSGLEN at a time and send the chunk to the host */
/* open file or die */
infile = fopen(filename, "r");
if(infile == NULL)
{
sprintf(errmsg, "File could not be read: %s", strerror(errno));
error(errmsg);
return;
}
/* now read in the file, MSGLEN at a time and send the chunk to the host */
for(cur_segment = 0; cur_segment < segments; cur_segment++)
{
fread(msg, MSGLEN, 1, infile);
@ -114,6 +126,7 @@ void send_file(int skt, const char *filename)
printf(errmsg);
send_message(skt, msg);
}
fclose(infile);
debug("Filesystem", "File sent successfully");
}

View File

@ -13,7 +13,7 @@
* The MAXFILE size is calculated to be the largest integer in CMDLEN - 1
* characters times MSGLEN. MAXFILE must be a multiple of MSGLEN.
*
* 9999 * 128 bytes = 1279872 bytes maximum
* 9999 segments * 128 bytes = 1279872 bytes maximum for example
*
*/
#define MAXFILE 1279872