Beispiel #1
0
void CALLBACK CBoxHttpServer::SendFile(ULONG_PTR dwParam)
{
	CSendFile* pSend = (CSendFile*)dwParam;
	BOOL bRet = 0;

	if(pSend->m_pBuf == NULL)
	{
		if(pSend->m_nPos == pSend->m_nSize)
		{
			//long l = sizeof(pSend->buf);
			long l = pSend->sizeofbuf;

			if(l > pSend->m_ullLen)
				l = pSend->m_ullLen;

			pSend->m_nPos = 0;
			pSend->m_nSize = pSend->m_pFile->Read(pSend->buf, l);
		}

		if(pSend->m_nSize)
			bRet = WriteFileEx((HANDLE)pSend->m_pSocket->m_hSocket, pSend->buf + pSend->m_nPos,
				pSend->m_nSize - pSend->m_nPos, pSend, IoCompletionRoutine);
	}else
		bRet = WriteFileEx((HANDLE)pSend->m_pSocket->m_hSocket, pSend->m_pBuf + pSend->m_ullStart,
				pSend->m_ullLen, pSend, IoCompletionRoutine);

	if(!bRet)
	{
		pSend->m_pSocket->Break();
		delete pSend;
	}
}
void VDAgent::write_completion(DWORD err, DWORD bytes, LPOVERLAPPED overlapped)
{
    VDAgent* a = _singleton;
    VDIChunk* chunk;
    DWORD count;

    ASSERT(!a->_message_queue.empty());
    if (err != 0) {
        vd_printf("vio_serial write completion error %lu", err);
        a->_running = false;
        return;
    }
    MUTEX_LOCK(a->_message_mutex);
    a->_write_pos += bytes;
    chunk = a->_message_queue.front();
    count = sizeof(VDIChunk) + chunk->hdr.size - a->_write_pos;
    if (count == 0) {
        a->_message_queue.pop();
        a->_write_pos = 0;
        delete chunk;
        if (!a->_message_queue.empty()) {
            chunk = a->_message_queue.front();
            count = sizeof(VDIChunk) + chunk->hdr.size;
        }
    }
    if (count) {
        if (!WriteFileEx(a->_vio_serial, (char*)chunk + a->_write_pos, count, overlapped,
                         write_completion) && GetLastError() != ERROR_IO_PENDING) {
            vd_printf("vio_serial write error %lu", GetLastError());
            a->_running = false;
        }
    }
    MUTEX_UNLOCK(a->_message_mutex);
}
Beispiel #3
0
// Must be called with the mutex held
static void initiate_write(struct win_handle *h) {
  struct write_buf *wbuf = h->write_head;
  if (h->write_pending || !wbuf) {
    return;
  }

  h->write_head = wbuf->next;
  if (!h->write_head) {
    h->write_tail = NULL;
  }

  h->write_pending = calloc(1, sizeof(*h->write_pending));
  h->write_pending->h = h;
  h->write_pending->wbuf = wbuf;

  if (!WriteFileEx(h->h, wbuf->cursor, wbuf->len, &h->write_pending->olap,
        write_completed)) {
    stream_debug("WriteFileEx: failed %s\n",
        win32_strerror(GetLastError()));
    free(h->write_pending);
    h->write_pending = NULL;
  } else {
    stream_debug("WriteFileEx: queued %d bytes for later\n", wbuf->len);
  }
}
Beispiel #4
0
static void overlapped_action(long action, long id,
                              HANDLE fd, char *buf, long len) {
  BOOL res;
  long err;
  completionData * d = GlobalAlloc(GPTR, sizeof(completionData));
  if (d == NULL) {
    errno = ENOMEM;
    uerror(action_name[action], Nothing);
  }
  d->id = id;
  d->action = action;

  D(printf("Starting %s: id %ld, len %ld\n", action_name[action], id, len));
  res =
    (action == READ_OVERLAPPED)?
    ReadFileEx(fd, buf, len, &(d->overlapped), overlapped_completion):
    WriteFileEx(fd, buf, len, &(d->overlapped), overlapped_completion);

  if (!res) {
    err = GetLastError ();
    if (err != ERROR_IO_PENDING) {
      win32_maperr (err);
  D(printf("Action %s failed: id %ld -> err %d (errCode %ld)\n",
           action_name[action], id, errno, err));
      uerror("ReadFileEx", Nothing);
    }
  }
}
Beispiel #5
0
BOOLEAN PacketSendPacket(
  LPADAPTER   AdapterObject,
  LPPACKET    lpPacket,
  BOOLEAN     Sync,
	BOOLEAN     RecyclingAllowed
)
{
  BOOLEAN  Result;

#if DEBUG_PACKETS
  D(bug("Packet32: PacketSendPacket bytes=%d, sync=%d\n",lpPacket->Length,Sync));
#endif

	lpPacket->OverLapped.Offset = 0;
	lpPacket->OverLapped.OffsetHigh = 0;
	lpPacket->bIoComplete = FALSE;

	if(Sync) {
		Result = WriteFile(
							AdapterObject->hFile,
							lpPacket->Buffer,
							lpPacket->Length,
							&lpPacket->BytesReceived,
							&lpPacket->OverLapped
							);
		if(Result) {
			Result = GetOverlappedResult(
									AdapterObject->hFile,
									&lpPacket->OverLapped,
									&lpPacket->BytesReceived,
									TRUE
									);
		} else {
			D(bug("Packet32: PacketSendPacket WriteFile failed, err=%d\n",(int)GetLastError()));
		}
		lpPacket->bIoComplete = TRUE;
		if(RecyclingAllowed) PacketFreePacket(lpPacket);
#if DEBUG_PACKETS
		D(bug("Packet32: PacketSendPacket result=%d, bytes=%d\n",(int)Result,(int)lpPacket->BytesReceived));
#endif
	} else {
		// don't care about the result
		Result = WriteFileEx(
			AdapterObject->hFile,
			lpPacket->Buffer,
			lpPacket->Length,
			&lpPacket->OverLapped,
			PacketSendCompletionRoutine
		);
#if DEBUG_PACKETS
		D(bug("Packet32: PacketSendPacket result=%d\n",(int)Result));
#endif
		if(!Result && RecyclingAllowed)	{
			recycle_write_packet(lpPacket);
		}
	}

  return Result;
}
Beispiel #6
0
static void comm_waitwrite(struct DosDeviceStruct *ptr)
{
	int bleft;

	bleft = ((ptr->obuf_tail <= ptr->obuf_head) ?
		ptr->obuf_head : ptr->obuf_size) - ptr->obuf_tail;
	WriteFileEx(ptr->handle,
		ptr->outbuf + ptr->obuf_tail,
		bleft,
		&ptr->write_ov,
		COMM16_WriteComplete);
}
Beispiel #7
0
	void WINAPI CompletedReadRoutine(DWORD dwErr,DWORD cbBytesRead,LPOVERLAPPED lpOverLap){
		LPPIPEINST lpPipeInst;
		BOOL fWrite = FALSE;
		lpPipeInst = (LPPIPEINST) lpOverLap;
		if ((dwErr == 0) && (cbBytesRead != 0)){
			GetAnswerToRequest(lpPipeInst);
			fWrite = WriteFileEx(lpPipeInst->hPipeInst,lpPipeInst->chReply,
				lpPipeInst->cbToWrite,(LPOVERLAPPED) lpPipeInst,
				(LPOVERLAPPED_COMPLETION_ROUTINE) CompletedWriteRoutine);
		}
		if (!fWrite) DisconnectAndClose(lpPipeInst);
	}
void SpectraVFSCached::Write(  size_t _nSpectraIndex, Spectra *_pSource )
{
	_cprintf("disk.write\n");
	assert( _pSource != NULL );

	size_t nBytesToWrite = TOTALCACHELINEBYTES;

	// check out of array bounds
	if ( _nSpectraIndex >= m_nNumberOfSpectra )
	{
		// total missed the bounds -> skip
		return;
	}

	// check for cacheline cropping
	if ( _nSpectraIndex+SpectraVFS::CACHELINESIZE >= m_nNumberOfSpectra )
	{
		// pre condition: _nIndex < m_nNumberOfSpectra 
		nBytesToWrite = (m_nNumberOfSpectra-_nSpectraIndex)*SPECTRASIZE;
	}

	DWORD ndwBytesToWrite = static_cast<DWORD>(nBytesToWrite);

	uint64_t nOffset = static_cast<uint64_t>(_nSpectraIndex)*SPECTRASIZE;
	uint32_t nOffsetLow, nOffsetHigh;
	Helpers::UInt64toHiLow( nOffset, nOffsetLow, nOffsetHigh );

	IOHandle writeHandle;
	writeHandle.set( nOffsetLow, nOffsetHigh );

	BOOL bWriteSuccess = FALSE;

#ifdef SPECTRAVFS_ASYNC_IO
	bWriteSuccess = WriteFileEx( m_FileHandle, _pSource, ndwBytesToWrite, &writeHandle.m_overlapped, &SpectraVFSCached::ReadFinished );
	WaitForIO( writeHandle );
#else
	DWORD ndwBytesWritten;
	bWriteSuccess = WriteFile( m_FileHandle, _pSource, ndwBytesToWrite, &ndwBytesWritten, &writeHandle.m_overlapped );
	if ( ndwBytesWritten != ndwBytesToWrite )
	{
		Helpers::print( std::string("SpectraVFSCached::Write Error: not all bytes written.\n"), &m_logFile );
		assert(0);
	}
#endif

	if ( bWriteSuccess == FALSE )
	{
		DWORD err = GetLastError();
		Helpers::print( std::string("SpectraVFSCached::Write Error:")+Helpers::numberToString<DWORD>(err)+std::string("\n"), &m_logFile );
	}
}
void CSerialPort::WriteEx(const void* lpBuf, DWORD dwCount)
{
  ASSERT(IsOpen());

  OVERLAPPED* pOverlapped = new OVERLAPPED;
  ZeroMemory(pOverlapped, sizeof(OVERLAPPED));
  pOverlapped->hEvent = (HANDLE) this;
  if (!WriteFileEx(m_hComm, lpBuf, dwCount, pOverlapped, _OnCompletion))
  {
    delete pOverlapped;
    TRACE(_T("Failed in call to WriteFileEx\n"));
    AfxThrowSerialException();
  }
}
Beispiel #10
0
int async_pipe_write(async_pipe_t pipe, const void* msg, int len, async_pipe_onwrite callback, void* param)
{
	Win32Pipe* o = (Win32Pipe*)pipe;
	o->write = callback;
	o->param = param;
	
	assert(1==InterlockedIncrement(&(o->ref)));
	if(!WriteFileEx(o->pipe, msg, len, &(o->overlap), winpipe_onwrite))
	{
		assert(0==InterlockedDecrement(&(o->ref)));
		return (int)GetLastError();
	}
	return 0;
}
Beispiel #11
0
bool Connection::AsyncWrite(
  const std::string& message, LPOVERLAPPED_COMPLETION_ROUTINE cb) {
  write_size_ = message.size();
#pragma warning(disable:4996)
  // already checked message length when push it into sendding queue
  message.copy(std::begin(write_buf_), write_size_);
#pragma warning(default:4996)

  auto write = WriteFileEx(
    pipe_.get(),
    write_buf_,
    write_size_,
    (LPOVERLAPPED)&io_overlap_,
    cb);
  return !!write;
}
Beispiel #12
0
static void wpa_supplicant_global_iface_rx(struct wpa_global_dst *dst,
					   size_t len)
{
	struct wpa_global *global = dst->priv->global;
	char *reply = NULL, *send_buf;
	size_t reply_len = 0, send_len;
	char *buf = dst->req_buf;

	dst->used = 1;
	if (len >= REQUEST_BUFSIZE)
		len = REQUEST_BUFSIZE - 1;
	buf[len] = '\0';

	reply = wpa_supplicant_global_ctrl_iface_process(global, buf,
							 &reply_len);
	if (reply) {
		send_buf = reply;
		send_len = reply_len;
	} else if (reply_len) {
		send_buf = "FAIL\n";
		send_len = 5;
	} else {
		os_free(dst->rsp_buf);
		dst->rsp_buf = NULL;
		return;
	}

	os_free(dst->rsp_buf);
	dst->rsp_buf = os_malloc(send_len);
	if (dst->rsp_buf == NULL) {
		global_close_pipe(dst);
		os_free(reply);
		return;
	}
	os_memcpy(dst->rsp_buf, send_buf, send_len);
	os_free(reply);

	if (!WriteFileEx(dst->pipe, dst->rsp_buf, send_len, &dst->overlap,
			 global_iface_write_completed)) {
		wpa_printf(MSG_DEBUG, "CTRL: WriteFileEx failed: %d",
			   (int) GetLastError());
		global_close_pipe(dst);
	} else {
		wpa_printf(MSG_DEBUG, "CTRL: Overlapped write started for %p",
			   dst);
	}
}
int qemu_create_pidfile(const char *filename)
{
    char buffer[128];
    int len;
#ifndef _WIN32
    int fd;

    fd = open(filename, O_RDWR | O_CREAT, 0600);
    if (fd == -1)
        return -1;

    if (lockf(fd, F_TLOCK, 0) == -1)
        return -1;

    len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
    if (write(fd, buffer, len) != len)
        return -1;
#else
    HANDLE file;
    DWORD flags;
    OVERLAPPED overlap;
    BOOL ret;

    /* Open for writing with no sharing. */
    file = CreateFile(filename, GENERIC_WRITE, 0, NULL,
		      OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

    if (file == INVALID_HANDLE_VALUE)
      return -1;

    flags = LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY;
    overlap.hEvent = 0;
    /* Lock 1 byte. */
    ret = LockFileEx(file, flags, 0, 0, 1, &overlap);
    if (ret == 0)
      return -1;

    /* Write PID to file. */
    len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
    ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
		      &overlap, NULL);
    if (ret == 0)
      return -1;
#endif
    return 0;
}
Beispiel #14
0
DWORD SpecialCases::Sp_WriteFileEx()
	{
	BOOL returnVal_Real = 0;
	BOOL returnVal_Intercepted = 0;
	
    HANDLE h = "";

	DWORD error = 0;
	DWORD dwBuffer = 0;
	
	LPOVERLAPPED lpo = new OVERLAPPED;
	lpo->hEvent = 0;
	lpo->Internal = 0;
	lpo->InternalHigh = 0;
	lpo->Offset = 0;
	lpo->OffsetHigh = 0;
	return(WriteFileEx(h, &dwBuffer, 0, lpo, NULL));
	}
Beispiel #15
0
//---------------------------------------------------------------------------
void __fastcall TForm1::bEnviaClick(TObject *Sender)
{
overLap.Internal = 0;
overLap.InternalHigh = 0;
overLap.Offset = 0;
overLap.OffsetHigh = 0;
overLap.hEvent = NULL;
log("Enviando Dados...");
bool retorno = WriteFileEx(
    hCom, 	// handle to output file
    /*LPCVOID*/ (LPCVOID)cOutput->Text.c_str(), 	// pointer to input buffer
    /*DWORD*/ cOutput->Text.Length(), 	// number of bytes to write
    /*LPOVERLAPPED*/ &overLap, 	// pointer to async. i/o data
    /*LPOVERLAPPED_COMPLETION_ROUTINE*/  FileIOCompletionRoutine // ptr. to completion routine
   );
log("Dados enviados.");
if (retorno) log("Envio = true");
else log("Envio = false");
}
Beispiel #16
0
static bool tap_send_packet(
	LPADAPTER fd,
	LPPACKET lpPacket,
	BOOLEAN Sync,
	BOOLEAN RecyclingAllowed)
{
	BOOLEAN Result;

	lpPacket->OverLapped.Offset = 0;
	lpPacket->OverLapped.OffsetHigh = 0;
	lpPacket->bIoComplete = FALSE;

	if (Sync) {
		Result = WriteFile(fd->hFile,
						   lpPacket->Buffer,
						   lpPacket->Length,
						   &lpPacket->BytesReceived,
						   &lpPacket->OverLapped);
		if (Result) {
			GetOverlappedResult(fd->hFile,
								&lpPacket->OverLapped,
								&lpPacket->BytesReceived,
								TRUE);
		}
		lpPacket->bIoComplete = TRUE;
		if (RecyclingAllowed)
			PacketFreePacket(lpPacket);
	}
	else {
		Result = WriteFileEx(fd->hFile,
							 lpPacket->Buffer,
							 lpPacket->Length,
							 &lpPacket->OverLapped,
							 tap_write_completion);

		if (!Result && RecyclingAllowed)
			recycle_write_packet(lpPacket);
	}

	return Result;
}
Beispiel #17
0
static void write_exec(ioent_t *io, event_t *evt) {
    DWORD error;
    int len;

    aio_count++;
    len = STRLEN(evt->val) - io->offset;
    if (len > io->bufsz) {
        len = io->bufsz;
    }
    /* 新規に書き込みIO発行 */
    memcpy(io->buf, STRPTR(evt->val)+io->offset, len);
    if (!WriteFileEx(io->handle, io->buf, len, &io->ctlblk, write_completion_handler)) {
        error = GetLastError();
        switch (error) {
        case ERROR_IO_PENDING:
            break;
        default:
            perr(PERR_SYSTEM, "WriteFile", error, __FILE__, __LINE__);
            return;
        }
    }
}
int qemu_create_pidfile(const char *filename)
{
    char buffer[128];
    int len;
    HANDLE file;
    OVERLAPPED overlap;
    BOOL ret;
    memset(&overlap, 0, sizeof(overlap));

    file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
		      OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

    if (file == INVALID_HANDLE_VALUE) {
        return -1;
    }
    len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
    ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
		      &overlap, NULL);
    if (ret == 0) {
        return -1;
    }
    return 0;
}
Beispiel #19
0
int qemu_create_pidfile(const char *filename)
{
    char buffer[128];
    int len;
#ifndef _WIN32
    int fd;

    fd = qemu_open(filename, O_RDWR | O_CREAT, 0600);
    if (fd == -1)
        return -1;

    if (lockf(fd, F_TLOCK, 0) == -1)
        return -1;

    len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
    if (write(fd, buffer, len) != len)
        return -1;
#else
    HANDLE file;
    OVERLAPPED overlap;
    BOOL ret;
    memset(&overlap, 0, sizeof(overlap));

    file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
		      OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

    if (file == INVALID_HANDLE_VALUE)
      return -1;

    len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
    ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
		      &overlap, NULL);
    if (ret == 0)
      return -1;
#endif
    return 0;
}
Beispiel #20
0
void UserSaveFile()
{
HWND H = (TabCtrl_GetCurSel(hwTab) == 5 ? hwOResEdit : hwMResEdit );

(LRESULT)BSize = (WPARAM)SendMessage(H,WM_GETTEXTLENGTH,0,0);
 
if(BSize>0)
{

// Initialize
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = FileWld;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = TEXT("Save File As");
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_HIDEREADONLY;

// Display the Save dialog box.

if (GetSaveFileName(&ofn)==TRUE)
 {
 	if(strlen(Ext)==0) strcat(Ext,".js");
 	if( strstr(szFile,Ext)==NULL ) strcat(szFile,Ext);

 	
  // verify existance
  hf = CreateFile(ofn.lpstrFile,
                    GENERIC_READ,
                    FILE_SHARE_READ,       // share for reading
                    (LPSECURITY_ATTRIBUTES) NULL,
                    OPEN_EXISTING,         // existing file only
                    FILE_ATTRIBUTE_NORMAL,
                    (HANDLE) NULL);	// address of structure with initialization data
  if(hf!=INVALID_HANDLE_VALUE)
  {
  	CloseHandle(hf);             
    if( MessageBox(hwnd, "File exists. Overwrite it?", ofn.lpstrFile, MB_YESNO )!=IDYES ) return;
  }
   
 hf = CreateFile(ofn.lpstrFile,
                    GENERIC_WRITE,
                    0,
                    (LPSECURITY_ATTRIBUTES) NULL,
                    CREATE_ALWAYS,         // existing file only
                    FILE_ATTRIBUTE_NORMAL,
                    (HANDLE) NULL);	// address of structure with initialization data
 if(hf==INVALID_HANDLE_VALUE)
  {
     MessageBox(hwnd, "Error! Can not write to file!", "", MB_OK );
  }
 else
  {
  	SrcPtr = malloc(BSize+1);
  	SendMessage(H,WM_GETTEXT,BSize+1,SrcPtr);
  	BSize = strlen(SrcPtr);	// recount
    if( WriteFileEx(hf, SrcPtr,  BSize, &ol, NULL) ){};     // write buffer to file
    CloseHandle(hf);
    free(SrcPtr);       // release memory block
  }
 }

}

}
Beispiel #21
0
MMRESULT
WdmAudCommitWaveBufferByLegacy(
    IN  PSOUND_DEVICE_INSTANCE SoundDeviceInstance,
    IN  PVOID OffsetPtr,
    IN  DWORD Length,
    IN  PSOUND_OVERLAPPED Overlap,
    IN  LPOVERLAPPED_COMPLETION_ROUTINE CompletionRoutine)
{
    HANDLE Handle;
    MMRESULT Result;
    PWDMAUD_DEVICE_INFO DeviceInfo;
    PSOUND_DEVICE SoundDevice;
    MMDEVICE_TYPE DeviceType;
    BOOL Ret;

    VALIDATE_MMSYS_PARAMETER( SoundDeviceInstance );
    VALIDATE_MMSYS_PARAMETER( OffsetPtr );
    VALIDATE_MMSYS_PARAMETER( Overlap );
    VALIDATE_MMSYS_PARAMETER( CompletionRoutine );

    GetSoundDeviceInstanceHandle(SoundDeviceInstance, &Handle);
    SND_ASSERT(Handle);

    Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);

    if ( ! MMSUCCESS(Result) )
    {
        return TranslateInternalMmResult(Result);
    }

    Result = GetSoundDeviceType(SoundDevice, &DeviceType);
    SND_ASSERT( Result == MMSYSERR_NOERROR );

    DeviceInfo = (PWDMAUD_DEVICE_INFO)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WDMAUD_DEVICE_INFO));
    if (!DeviceInfo)
    {
        // no memory
        return MMSYSERR_NOMEM;
    }

    DeviceInfo->Header.FrameExtent = Length;
    if (DeviceType == WAVE_OUT_DEVICE_TYPE)
    {
        DeviceInfo->Header.DataUsed = Length;
    }
    DeviceInfo->Header.Data = OffsetPtr;
    DeviceInfo->Header.Size = sizeof(WDMAUD_DEVICE_INFO);
    DeviceInfo->Header.PresentationTime.Numerator = 1;
    DeviceInfo->Header.PresentationTime.Denominator = 1;
    DeviceInfo->hDevice = Handle;
    DeviceInfo->DeviceType = DeviceType;


    // create completion event
    Overlap->Standard.hEvent = Handle = CreateEventW(NULL, FALSE, FALSE, NULL);
    if (Overlap->Standard.hEvent == NULL)
    {
        // no memory
        HeapFree(GetProcessHeap(), 0, DeviceInfo);
        return MMSYSERR_NOMEM;
    }

    Overlap->OriginalCompletionRoutine = CompletionRoutine;
    Overlap->CompletionContext = (PVOID)DeviceInfo;

    if (DeviceType == WAVE_OUT_DEVICE_TYPE)
    {
        Ret = WriteFileEx(KernelHandle, DeviceInfo, sizeof(WDMAUD_DEVICE_INFO), (LPOVERLAPPED)Overlap, LegacyCompletionRoutine);
        if (Ret)
            WaitForSingleObjectEx (KernelHandle, INFINITE, TRUE);
    }
    else if (DeviceType == WAVE_IN_DEVICE_TYPE)
    {
        Ret = ReadFileEx(KernelHandle, DeviceInfo, sizeof(WDMAUD_DEVICE_INFO), (LPOVERLAPPED)Overlap, LegacyCompletionRoutine);
        if (Ret)
            WaitForSingleObjectEx (KernelHandle, INFINITE, TRUE);
    }

    // close event handle
    CloseHandle(Handle);

    return MMSYSERR_NOERROR;
}
Beispiel #22
0
static void wpa_supplicant_ctrl_iface_rx(struct wpa_ctrl_dst *dst, size_t len)
{
	struct wpa_supplicant *wpa_s = dst->priv->wpa_s;
	char *reply = NULL, *send_buf;
	size_t reply_len = 0, send_len;
	int new_attached = 0;
	char *buf = dst->req_buf;

	dst->used = 1;
	if (len >= REQUEST_BUFSIZE)
		len = REQUEST_BUFSIZE - 1;
	buf[len] = '\0';

	if (os_strcmp(buf, "ATTACH") == 0) {
		dst->attached = 1;
		wpa_printf(MSG_DEBUG, "CTRL_IFACE monitor attached");
		new_attached = 1;
		reply_len = 2;
	} else if (os_strcmp(buf, "DETACH") == 0) {
		dst->attached = 0;
		wpa_printf(MSG_DEBUG, "CTRL_IFACE monitor detached");
		reply_len = 2;
	} else if (os_strncmp(buf, "LEVEL ", 6) == 0) {
		wpa_printf(MSG_DEBUG, "CTRL_IFACE LEVEL %s", buf + 6);
		dst->debug_level = atoi(buf + 6);
		reply_len = 2;
	} else {
		reply = wpa_supplicant_ctrl_iface_process(wpa_s, buf,
							  &reply_len);
	}

	if (reply) {
		send_buf = reply;
		send_len = reply_len;
	} else if (reply_len == 2) {
		send_buf = "OK\n";
		send_len = 3;
	} else {
		send_buf = "FAIL\n";
		send_len = 5;
	}

	os_free(dst->rsp_buf);
	dst->rsp_buf = os_malloc(send_len);
	if (dst->rsp_buf == NULL) {
		ctrl_close_pipe(dst);
		os_free(reply);
		return;
	}
	os_memcpy(dst->rsp_buf, send_buf, send_len);
	os_free(reply);

	if (!WriteFileEx(dst->pipe, dst->rsp_buf, send_len, &dst->overlap,
			 ctrl_iface_write_completed)) {
		wpa_printf(MSG_DEBUG, "CTRL: WriteFileEx failed: %d",
			   (int) GetLastError());
		ctrl_close_pipe(dst);
	} else {
		wpa_printf(MSG_DEBUG, "CTRL: Overlapped write started for %p",
			   dst);
	}

	if (new_attached)
		eapol_sm_notify_ctrl_attached(wpa_s->eapol);
}