Example #1
0
int asyncFileWriteStart(AsyncFile *f, int fPosition, void *bufferPtr, int bufferSize) {
  /* Start an asynchronous operation to write bufferSize bytes to the given file
	 starting at the given file position. The file's semaphore will be signalled when
	 the operation is complete. The client may then use asyncFileWriteResult() to
	 find out if the operation succeeded and how many bytes were actually written. */

	AsyncFileState *state;
	OSErr err;

	if (!asyncFileValid(f)) return success(false);
	state = f->state;
	if (state->status == BUSY) return success(false);  /* operation in progress */
	if (!state->writable) return success(false);

	/* allocate a new buffer if necessary */
	asyncFileAllocateBuffer(state, bufferSize);
	if (state->bufferPtr == nil) return success(false);  /* could not allocate buffer */

	/* copy the squeak buffer into the file buffer */
	memcpy(state->bufferPtr, bufferPtr, bufferSize);

	asyncFileInitPB(state, fPosition);
	err = PBWriteAsync(&state->pb);
	if (err != noErr) {
		state->status = IDLE;
		return success(false);
	}
	return 0;
}
Example #2
0
int asyncFileWriteStart(AsyncFile *f, int fPosition, int bufferPtr, int bufferSize) {
  /* Start an asynchronous operation to write bufferSize bytes to the given file
     starting at the given file position. The file''s semaphore will be signalled when
     the operation is complete. The client may then use asyncFileWriteResult() to
     find out if the operation succeeded and how many bytes were actually written. */
  AsyncFileState *state = (AsyncFileState *) f->state;

  if (!asyncFileValid(f)) return success(false);
  if (state->status == BUSY) return success(false);  /* operation in progress */
  if (!state->writable) return success(false);

  /* allocate a new buffer if necessary */
  asyncFileAllocateBuffer(state, bufferSize);
  if (state->bufferPtr == NULL) return success(false);  /* could not allocate buffer */

  /* copy the squeak buffer into the file buffer */
  MoveMemory((void*)state->bufferPtr, (void*) bufferPtr, bufferSize);

  state->dwPosition = fPosition;
  state->dwSize = bufferSize;
  state->status = BUSY;
  state->rFlag = FALSE;
  SetEvent(state->hEvent);
  return 1;
}
Example #3
0
int asyncFileReadStart(AsyncFile *f, int fPosition, int count) {
  /* Start an asynchronous operation to read count bytes from the given file
	 starting at the given file position. The file's semaphore will be signalled when
	 the operation is complete. The client may then use asyncFileReadResult() to
	 find out if the operation succeeded and to get the data that was read. */

	AsyncFileState *state;
	OSErr err;

	if (!asyncFileValid(f)) return success(false);
	state = f->state;
	if (state->status == BUSY) return success(false);  /* operation in progress */

	/* allocate a new buffer if necessary */
	asyncFileAllocateBuffer(state, count);
	if (state->bufferPtr == nil) return success(false);  /* could not allocate buffer */

	asyncFileInitPB(state, fPosition);
	err = PBReadAsync(&state->pb);
	if (err != noErr) {
		state->status = IDLE;
		success(false);
		return 0;
	}
	return 0;
}
Example #4
0
int asyncFileReadStart(AsyncFile *f, int fPosition, int count) {
  /* Start an asynchronous operation to read count bytes from the given file
     starting at the given file position. The file''s semaphore will be signalled when
     the operation is complete. The client may then use asyncFileReadResult() to
     find out if the operation succeeded and to get the data that was read. */
  AsyncFileState *state = (AsyncFileState *) f->state;
  
  if (!asyncFileValid(f)) return success(false);
  if (state->status == BUSY) return success(false);  /* operation in progress */
  
  /* allocate a new buffer if necessary */
  asyncFileAllocateBuffer(state, count);
  if (state->bufferPtr == NULL) return success(false);  /* could not allocate buffer */

  state->dwPosition = fPosition;
  state->dwSize = count;
  state->status = BUSY;
  state->rFlag = TRUE;
  SetEvent(state->hEvent);
  return 1;
}