OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

[/] [plasma/] [trunk/] [kernel/] [netutil.c] - Diff between revs 215 and 225

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 215 Rev 225
Line 66... Line 66...
 
 
 
 
static void FtpdReceiver(IPSocket *socket)
static void FtpdReceiver(IPSocket *socket)
{
{
   unsigned char buf[600];
   unsigned char buf[600];
   int bytes;
   int bytes, state = socket->state;
   FtpdInfo *info = (FtpdInfo*)socket->userPtr;
   FtpdInfo *info = (FtpdInfo*)socket->userPtr;
 
 
   if(info == NULL || info->done)
   if(info == NULL || info->done)
      return;
      return;
   if(socket->state > IP_TCP)
   do
 
   {
 
      bytes = IPRead(socket, buf, sizeof(buf));
 
      fwrite(buf, 1, bytes, info->file);
 
   } while(bytes);
 
   if(state > IP_TCP)
   {
   {
      fclose(info->file);
      fclose(info->file);
      IPClose(socket);
      IPClose(socket);
      info->done = 1;
      info->done = 1;
      IPPrintf(info->socket, "226 Done\r\n");
      IPPrintf(info->socket, "226 Done\r\n");
      return;
      return;
   }
   }
   bytes = IPRead(socket, buf, sizeof(buf));
 
   fwrite(buf, 1, bytes, info->file);
 
}
}
 
 
 
 
static void FtpdServer(IPSocket *socket)
static void FtpdServer(IPSocket *socket)
{
{
Line 192... Line 195...
} FtpInfo;
} FtpInfo;
 
 
 
 
static void FtpCallbackTransfer(IPSocket *socket)
static void FtpCallbackTransfer(IPSocket *socket)
{
{
   int bytes;
   int bytes, state = socket->state;
   FtpInfo *info = (FtpInfo*)socket->userPtr;
   FtpInfo *info = (FtpInfo*)socket->userPtr;
 
 
   //printf("FtpCallbackTransfer\n");
   //printf("FtpCallbackTransfer\n");
   if(info == NULL)
   if(info == NULL)
      return;
      return;
Line 204... Line 207...
   if(info->send == 0)
   if(info->send == 0)
      bytes = IPRead(socket, info->buf + info->bytes, bytes);
      bytes = IPRead(socket, info->buf + info->bytes, bytes);
   else
   else
      bytes = IPWrite(socket, info->buf + info->bytes, bytes);
      bytes = IPWrite(socket, info->buf + info->bytes, bytes);
   info->bytes += bytes;
   info->bytes += bytes;
   if(info->bytes == info->size || socket->state > IP_TCP)
   if(info->bytes == info->size || (bytes == 0 && state > IP_TCP))
   {
   {
      socket->userFunc(info->buf, info->bytes);
      socket->userFunc(info->buf, info->bytes);
      free(info);
      free(info);
      socket->userPtr = NULL;
      socket->userPtr = NULL;
      IPClose(socket);
      IPClose(socket);
Line 381... Line 384...
      memcpy((uint8*)socket->userPtr + blockNum * 512 - 512, buf+4, bytes-4);
      memcpy((uint8*)socket->userPtr + blockNum * 512 - 512, buf+4, bytes-4);
      buf[1] = 4; //ACK
      buf[1] = 4; //ACK
      IPWrite(socket, buf, 4);
      IPWrite(socket, buf, 4);
      if(bytes-4 < 512)
      if(bytes-4 < 512)
      {
      {
         printf("Done %d bytes\n", length);
 
         socket->userFunc(socket->userPtr, length);
         socket->userFunc(socket->userPtr, length);
         IPClose(socket);
         IPClose(socket);
      }
      }
   }
   }
}
}
Line 746... Line 748...
 
 
 
 
static void ConsoleCat(IPSocket *socket, char *command)
static void ConsoleCat(IPSocket *socket, char *command)
{
{
   char buf[COMMAND_BUFFER_SIZE], name[80];
   char buf[COMMAND_BUFFER_SIZE], name[80];
   int bytes;
   int bytes, bytes2;
   FILE *file;
   FILE *file;
   sscanf(command, "%s %s\n", buf, name);
   sscanf(command, "%s %s\n", buf, name);
   file = fopen(name, "r");
   file = fopen(name, "r");
   if(file)
   if(file)
   {
   {
      for(;;)
      for(;;)
      {
      {
         bytes = fread(buf, 1, sizeof(buf), file);
         bytes = fread(buf, 1, sizeof(buf), file);
         if(bytes == 0)
         if(bytes == 0)
            break;
            break;
         IPWrite(socket, (uint8*)buf, bytes);
         bytes2 = IPWrite(socket, (uint8*)buf, bytes);
 
         if(bytes != bytes2)
 
            printf("(%d %d) ", bytes, bytes2);
      }
      }
      fclose(file);
      fclose(file);
   }
   }
   IPPrintf(socket, "\r\n");
   IPPrintf(socket, "\r\n");
}
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.