Blame src/FileCopyOutputJob.cc

Packit 8f70b4
/*
Packit 8f70b4
 * lftp - file transfer program
Packit 8f70b4
 *
Packit 8f70b4
 * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net)
Packit 8f70b4
 *
Packit 8f70b4
 * This program is free software; you can redistribute it and/or modify
Packit 8f70b4
 * it under the terms of the GNU General Public License as published by
Packit 8f70b4
 * the Free Software Foundation; either version 3 of the License, or
Packit 8f70b4
 * (at your option) any later version.
Packit 8f70b4
 *
Packit 8f70b4
 * This program is distributed in the hope that it will be useful,
Packit 8f70b4
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8f70b4
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8f70b4
 * GNU General Public License for more details.
Packit 8f70b4
 *
Packit 8f70b4
 * You should have received a copy of the GNU General Public License
Packit 8f70b4
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 8f70b4
 */
Packit 8f70b4
Packit 8f70b4
#include <config.h>
Packit 8f70b4
#include "FileCopy.h"
Packit 8f70b4
#include "FileCopyOutputJob.h"
Packit 8f70b4
Packit 8f70b4
FileCopyPeerOutputJob::FileCopyPeerOutputJob(const JobRef<OutputJob>& new_o)
Packit 8f70b4
   : FileCopyPeer(PUT), o(new_o)
Packit 8f70b4
{
Packit 8f70b4
   DontCopyDate();
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
int FileCopyPeerOutputJob::Put_LL(const char *buf,int len)
Packit 8f70b4
{
Packit 8f70b4
   off_t io_at=pos;
Packit 8f70b4
   if(GetRealPos()!=io_at) // GetRealPos can alter pos.
Packit 8f70b4
      return 0;
Packit 8f70b4
Packit 8f70b4
   if(len==0 && eof)
Packit 8f70b4
      return 0;
Packit 8f70b4
Packit 8f70b4
   if(o->Full())
Packit 8f70b4
      return 0;
Packit 8f70b4
Packit 8f70b4
   o->Put(buf,len);
Packit 8f70b4
Packit 8f70b4
   seek_pos+=len; // mainly to indicate that there was some output.
Packit 8f70b4
   return len;
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
int FileCopyPeerOutputJob::Do()
Packit 8f70b4
{
Packit 8f70b4
   int m=STALL;
Packit 8f70b4
Packit 8f70b4
   if(broken || done)
Packit 8f70b4
      return m;
Packit 8f70b4
   if(o->Error())
Packit 8f70b4
   {
Packit 8f70b4
      broken=true;
Packit 8f70b4
      return MOVED;
Packit 8f70b4
   }
Packit 8f70b4
   if(eof && Size()==0)
Packit 8f70b4
   {
Packit 8f70b4
      done=true;
Packit 8f70b4
      return MOVED;
Packit 8f70b4
   }
Packit 8f70b4
Packit 8f70b4
   if(!write_allowed)
Packit 8f70b4
      return m;
Packit 8f70b4
Packit 8f70b4
   while(Size()>0)
Packit 8f70b4
   {
Packit 8f70b4
      int res=Put_LL(buffer+buffer_ptr,Size());
Packit 8f70b4
      if(res>0)
Packit 8f70b4
      {
Packit 8f70b4
	 buffer_ptr+=res;
Packit 8f70b4
	 m=MOVED;
Packit 8f70b4
      }
Packit 8f70b4
      if(res<0)
Packit 8f70b4
	 return MOVED;
Packit 8f70b4
      if(res==0)
Packit 8f70b4
	 break;
Packit 8f70b4
   }
Packit 8f70b4
   return m;
Packit 8f70b4
}
Packit 8f70b4
Packit 8f70b4
void FileCopyPeerOutputJob::Fg()
Packit 8f70b4
{
Packit 8f70b4
   o->Fg();
Packit 8f70b4
   FileCopyPeer::Fg();
Packit 8f70b4
}
Packit 8f70b4
void FileCopyPeerOutputJob::Bg()
Packit 8f70b4
{
Packit 8f70b4
   o->Bg();
Packit 8f70b4
   FileCopyPeer::Bg();
Packit 8f70b4
}