示例#1
0
sBool sMiniFTPClient::PutFile(const sChar *filename,sFile *readFrom)
{
  sSize currentPos = 0;
  sSize totalSize = readFrom->GetSize();
  if(State == CS_NOTARGET)
    return sFALSE;

  for(;;)
  {
    if(State != CS_CONNECTED && !TryReconnect(RetryCount))
      break;

    if(!ContinueUploads)
      currentPos = 0;

    if(SendCommand(sMFC_PUT,filename,currentPos))
    {
      sU8 sizeBuf[8];
      sUnalignedLittleEndianStore64(sizeBuf,totalSize);
      if(!WriteAll(sizeBuf,8))
        continue;

      if(!Progress(filename,currentPos,totalSize,ProgressUser))
        return MaybeNextTime();

      sFixedArray<sU8> ioBuf(FileIOBufferSize);

      while(currentPos < totalSize)
      {
        sInt size = (sInt) sMin<sS64>(totalSize-currentPos,ioBuf.GetSize());
        if(!readFrom->Read(&ioBuf[0],size))
          return MaybeNextTime();

        if(!WriteAll(&ioBuf[0],size))
          break;

        currentPos += size;
        if(!Progress(filename,currentPos,totalSize,ProgressUser))
          return sFALSE;
      }

      if(currentPos == totalSize)
        return sTRUE;
    }
    else if(Error == sMFE_OK)
      MaybeNextTime();
    else
      break;
  }

  return sFALSE;
}
示例#2
0
sBool sMiniFTPClient::SendCommand(sInt command,const sChar *filename,sSize extra)
{
  static const sInt maxFilenameLen = 1024;
  sVERIFY(filename != 0);

  Error = sMFE_OK;

  sInt filenameLen = sGetStringLen(filename);
  sVERIFY(filenameLen < maxFilenameLen);
  sVERIFYSTATIC(sizeof(sChar) == 2);

  sU8 header[16];
  sUnalignedLittleEndianStore32(header+ 0,command);
  sUnalignedLittleEndianStore32(header+ 4,filenameLen);
  sUnalignedLittleEndianStore64(header+ 8,extra);
  if(!WriteAll(header,16))
    return sFALSE;

  sU8 *stringBuf = (sU8*) sALLOCSTACK(sChar,filenameLen*2);
  for(sInt i=0;i<filenameLen;i++)
    sUnalignedLittleEndianStore16(stringBuf + i*2,filename[i]);

  if(!WriteAll(stringBuf,filenameLen*2))
    return sFALSE;

  // read answer code
  sU8 answer;
  if(!ReadAll(&answer,1))
    return sFALSE;

  if(answer == sMFE_OK) // no error
    return sTRUE;
  else
  {
    Error = (sMiniFTPError) answer;
    return sFALSE;
  }
}
/*
 * Returns number of detected but correctable errors.
 */
int GioCopy(struct Gio *src, struct Gio *dst) {
  char buffer[COPY_CHUNKSIZE];
  ssize_t bytes_read;
  int num_errors = 0;

  while (0 != (bytes_read = (*NACL_VTBL(Gio, src)->
                             Read)(src, buffer, sizeof buffer))) {
    if (bytes_read < 0) {
      fprintf(stderr, "negative read?!?\n");
      return ++num_errors;
    }
    num_errors += WriteAll(dst, buffer, (size_t) bytes_read);
  }
  return num_errors;
}
示例#4
0
bool ProxySession::WriteOutputTo(FileDesc& dest, std::error_code &ec)
{
    while(!ec && !this->m_output_vec.empty())
    {
        RSlice slice = m_output_vec.front();
        m_output_vec.pop_front();

        WriteAll(dest, slice, ec);
    }

    // in case of write failure, just clear the vec
    m_output_vec.clear();

    return ec.value();
}
示例#5
0
nsresult
TestPipe(nsIInputStream* in, nsIOutputStream* out)
{
    nsresult rv;
    nsIThread* thread;
    nsReceiver* receiver = new nsReceiver(in);
    if (receiver == nsnull) return NS_ERROR_OUT_OF_MEMORY;
    NS_ADDREF(receiver);

    rv = NS_NewThread(&thread, receiver);
    if (NS_FAILED(rv)) return rv;

    PRUint32 total = 0;
    PRIntervalTime start = PR_IntervalNow();
    for (PRUint32 i = 0; i < ITERATIONS; i++) {
        PRUint32 writeCount;
        char *buf = PR_smprintf("%d %s", i, kTestPattern);
        PRUint32 len = strlen(buf);
        rv = WriteAll(out, buf, len, &writeCount);
        if (gTrace) {
            printf("wrote: ");
            for (PRUint32 j = 0; j < writeCount; j++) {
                putc(buf[j], stdout);
            }
            printf("\n");
        }
        PR_smprintf_free(buf);
        if (NS_FAILED(rv)) return rv;
        total += writeCount;
    }
    rv = out->Close();
    if (NS_FAILED(rv)) return rv;

    PRIntervalTime end = PR_IntervalNow();

    thread->Shutdown();

    printf("wrote %d bytes, time = %dms\n", total,
           PR_IntervalToMilliseconds(end - start));
    NS_ASSERTION(receiver->GetBytesRead() == total, "didn't read everything");

    NS_RELEASE(thread);
    NS_RELEASE(receiver);

    return NS_OK;
}
示例#6
0
nsresult
TestShortWrites(nsIInputStream* in, nsIOutputStream* out)
{
    nsresult rv;
    nsIThread* thread;
    nsShortReader* receiver = new nsShortReader(in);
    if (receiver == nsnull) return NS_ERROR_OUT_OF_MEMORY;
    NS_ADDREF(receiver);

    rv = NS_NewThread(&thread, receiver);
    if (NS_FAILED(rv)) return rv;

    PRUint32 total = 0;
    for (PRUint32 i = 0; i < ITERATIONS; i++) {
        PRUint32 writeCount;
        char* buf = PR_smprintf("%d %s", i, kTestPattern);
        PRUint32 len = strlen(buf);
        len = len * rand() / RAND_MAX;
        len = PR_MAX(1, len);
        rv = WriteAll(out, buf, len, &writeCount);
        if (NS_FAILED(rv)) return rv;
        NS_ASSERTION(writeCount == len, "didn't write enough");
        total += writeCount;

        if (gTrace)
            printf("wrote %d bytes: %s\n", writeCount, buf);
        PR_smprintf_free(buf);
        //printf("calling Flush\n");
        out->Flush();
        //printf("calling WaitForReceipt\n");
        PRUint32 received = receiver->WaitForReceipt();
        NS_ASSERTION(received == writeCount, "received wrong amount");
    }
    rv = out->Close();
    if (NS_FAILED(rv)) return rv;

    thread->Shutdown();
    printf("wrote %d bytes\n", total);

    NS_RELEASE(thread);
    NS_RELEASE(receiver);

    return NS_OK;
}
示例#7
0
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//
void Next()
{
  GetProjection(event, event);
  
  FindEdges(); 

  if( (start[1]-start[0])> MinStartDist ) // limit the burst distance
    {
      GetAmpSignals();
      
      GetPMTSignals();
      
      GetShpSignals();

      if( !(event%100) )
	{
	  DrawAll();  
	  DrawDistributions();
	  PrintAll();
	  printf("event: %i\n", event);
	}  
    }
  event++;

  if( event == event_lastt )
    {
      ftimer.Stop();
                  
      FitProfiles();
      
      PrintAll();

      DrawAll();  

      DrawDistributions();

      WriteAll();
      
      gSystem->Exit(1);
    }
}
int GioRevCopy(struct Gio *src, struct Gio *dst) {
  off_t file_size;
  char buffer[COPY_CHUNKSIZE];
  off_t start_offset;
  int num_errors = 0;
  size_t expected_bytes;

  file_size = (*NACL_VTBL(Gio, src)->Seek)(src, 0, SEEK_END);
  if (file_size <= 0) {
    fprintf(stderr, "non-positive file size?!?\n");
  }

  start_offset = file_size;
  do {
    start_offset -= COPY_CHUNKSIZE;
    expected_bytes = COPY_CHUNKSIZE;
    if (start_offset < 0) {
      expected_bytes = start_offset + COPY_CHUNKSIZE;
      start_offset = 0;
    }
    if (start_offset != (*NACL_VTBL(Gio, src)->
                         Seek)(src, start_offset, SEEK_SET)) {
      fprintf(stderr, "seek in source file failed, offset %"NACL_PRId64"\n",
              (int64_t) start_offset);
      return ++num_errors;
    }
    num_errors += ReadAll(src, buffer, expected_bytes);
    if (start_offset != (*NACL_VTBL(Gio, dst)->
                         Seek)(dst, start_offset, SEEK_SET)) {
      fprintf(stderr, "seek in destination file failed, offset"
              " %"NACL_PRId64"\n", (int64_t) start_offset);
      return ++num_errors;
    }
    num_errors += WriteAll(dst, buffer, expected_bytes);
  } while (start_offset > 0);

  return num_errors;
}
示例#9
0
文件: mesh.c 项目: EricPascolo/shyfem
int main(int argc, char *argv[])

{
	int ntotal,external;
	NodeList hull, intern, boundary, given;

	HNN=MakeHashTable();
	HEL=MakeHashTable();
	HLI=MakeHashTable();
	NEL=MakeListTable();
	CM=MakeQueueTable();

 	SetOptions(argc,argv);

	ReadFiles(argc,argv);
	/* CheckBoundary(); */

	ntotal = CheckInput();
	hull = MakeNodeList(ntotal);
	intern = MakeNodeList(ntotal);

	printf("Making convex hull... %d\n",hull->count);
	ConvexHull(hull,intern);
/*
	CheckConvex(hull,intern);
	PrintNodeList("hull",hull);
	PrintNodeList("intern",intern);
*/

	printf("Making maxi elements...\n");
	MakeMaxiTriang(hull);
	CheckNeibor(-1);

	printf("Inserting convex hull... %d\n",hull->count);
	InsertBoundaryNodes(hull);
	CheckCircumCircle();
	CheckNeibor(-2);

	WriteAll("M_hull.grd",hull);
	CheckNeibor(-3);

	printf("Inserting internal boundary points... %d\n",intern->count);
	InsertBoundaryNodes(intern);
	CheckCircumCircle();
	CheckNeibor(-4);
	WriteAll("M_orgbound.grd",NULL);

	SetResolution(hull);
	CopyBoundaryLine();

	printf("Recovering boundary lines 1...\n");
	RecoverBoundary();
	CheckCircumCircle();
	CheckNeibor(-43);
	WriteAll("M_bndrecover.grd",NULL);

	printf("Refining boundary points 1...\n");
	boundary = RefineBoundary();

	if( boundary ) {
	    printf("Inserting new boundary points... %d\n",boundary->count);
	    InsertBoundaryNodes(boundary);
	    CheckCircumCircle();
	    CheckCircumCircleProperty();
	    CheckNeibor(-5);
	}

	TestVersion();

	printf("Marking external elements...");
	external=MarkExternalElements( hull );
	printf(" %d / %d\n",external,NTotElems);
	WriteGrd("M_finebound.grd");

/*
	printf("Marking outer elements...");
	external=MarkOuterElements();
	printf(" %d / %d\n",external,NTotElems);
	WriteGrd("M_test.grd");
*/

	FreeNodeList(hull);
	FreeNodeList(intern);
	FreeNodeList(boundary);

	given = GivenNodes();
	printf("Inserting internal given points... %d\n",given->count);
	InsertNodes(given);
	FreeNodeList(given);
	CheckCircumCircle();
	CheckNeibor(-44);
	WriteAll("M_given.grd",NULL);

	printf("Recovering boundary lines 2...\n");
	RecoverBoundary();
	CheckCircumCircle();
	CheckNeibor(-45);
	WriteAll("M_intrecover.grd",NULL);

	CheckArea();
	printf("Inserting internal points...\n");
	InsertInternalNodes();
	CheckCircumCircle();
	CheckCircumCircleProperty();
	WriteGrd("M_insert.grd");

	TestVersion();

	CheckArea();
	printf("Refining internal points... %f\n",OpAspect);
	RefineInternalNodes();
	CheckArea();
	CheckCircumCircle();
	CheckCircumCircleProperty();
	WriteGrd("M_refine.grd");

	CheckArea();
	printf("Recovering boundary lines 3...\n");
	RecoverBoundary();
	printf("Recovering fault lines...\n");
	RecoverInternalFault();
	CheckCircumCircle();
	CheckNeibor(-48);
	WriteAll("M_intrecover2.grd",NULL);

	printf("Marking outer elements...");
	external=MarkOuterElements();
	printf(" %d / %d\n",external,NTotElems);
	printf("Marking outer nodes...");
	external=MarkOuterNodes();
	printf(" %d / %d\n",external,NTotNodes);
	WriteGrd("M_test.grd");

	TestVersion();

	CheckArea();
	printf("Smoothing internal points... %f\n",OpSmoothOmega);
	SmoothInternalNodes();
	CheckArea();
	WriteGrd("final.grd");

	return 0;
}
示例#10
0
		void TextFile::WriteAll(CStr fileName, String text)
		{
			WriteAll(fileName, text, text.Length());
		}
示例#11
0
		void TextFile::WriteAll(CStr fileName, CStr text)
		{
			WriteAll(fileName, text, String::CStrLength(text));
		}
EXPORT_C void CSenLogger::WriteAllWithClientId(TInt aClientId, TInt aChannel, TInt aLevel, const TDesC8& aText)
    {
    // Write client id on separate line, for clarity & simplicity
    WriteFormat( aChannel, aLevel, KClientIdFmtNextLine8, aClientId);
    WriteAll( aChannel, aLevel, aText );
    }
示例#13
0
bool WriteAllUtf(const char *filePath, const void *data, size_t dataLen)
{
    WCHAR buf[512];
    str::Utf8ToWcharBuf(filePath, str::Len(filePath), buf, dimof(buf));
    return WriteAll(buf, data, dataLen);
}
示例#14
0
nsresult
TestChainedPipes()
{
    nsresult rv;
    printf("TestChainedPipes\n");

    nsIInputStream* in1;
    nsIOutputStream* out1;
    rv = NS_NewPipe(&in1, &out1, 20, 1999);
    if (NS_FAILED(rv)) return rv;

    nsIInputStream* in2;
    nsIOutputStream* out2;
    rv = NS_NewPipe(&in2, &out2, 200, 401);
    if (NS_FAILED(rv)) return rv;

    nsIThread* thread;
    nsPump* pump = new nsPump(in1, out2);
    if (pump == nsnull) return NS_ERROR_OUT_OF_MEMORY;
    NS_ADDREF(pump);

    rv = NS_NewThread(&thread, pump);
    if (NS_FAILED(rv)) return rv;

    nsIThread* receiverThread;
    nsReceiver* receiver = new nsReceiver(in2);
    if (receiver == nsnull) return NS_ERROR_OUT_OF_MEMORY;
    NS_ADDREF(receiver);

    rv = NS_NewThread(&receiverThread, receiver);
    if (NS_FAILED(rv)) return rv;

    PRUint32 total = 0;
    for (PRUint32 i = 0; i < ITERATIONS; i++) {
        PRUint32 writeCount;
        char* buf = PR_smprintf("%d %s", i, kTestPattern);
        PRUint32 len = strlen(buf);
        len = len * rand() / RAND_MAX;
        len = PR_MAX(1, len);
        rv = WriteAll(out1, buf, len, &writeCount);
        if (NS_FAILED(rv)) return rv;
        NS_ASSERTION(writeCount == len, "didn't write enough");
        total += writeCount;

        if (gTrace)
            printf("wrote %d bytes: %s\n", writeCount, buf);

        PR_smprintf_free(buf);
    }
    printf("wrote total of %d bytes\n", total);
    rv = out1->Close();
    if (NS_FAILED(rv)) return rv;

    thread->Shutdown();
    receiverThread->Shutdown();

    NS_RELEASE(thread);
    NS_RELEASE(pump);
    NS_RELEASE(receiverThread);
    NS_RELEASE(receiver);
    return NS_OK;
}