当前位置: 首页>>代码示例>>C++>>正文


C++ LastError函数代码示例

本文整理汇总了C++中LastError函数的典型用法代码示例。如果您正苦于以下问题:C++ LastError函数的具体用法?C++ LastError怎么用?C++ LastError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了LastError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: EmbedSend

/* The send embedded callback
 *  return : nb bytes sended
 *           -1 : other errors (unexpected)
 *           -2 : want write
 *           -3 : connexion reset
 *           -4 : interrupt
 *           -5 : pipe error / connection closed
 */
int EmbedSend(char *buf, int sz, void *ctx)
{
    int socket = *(int*)ctx;
    int sent;
    int len = sz;

    sent = SEND_FUNCTION(socket, &buf[sz - len], len, 0);

    if (sent == -1) {
        if (LastError() == SOCKET_EWOULDBLOCK || 
            LastError() == SOCKET_EAGAIN)
            return -2;

        else if (LastError() == SOCKET_ECONNRESET)
            return -3;

        else if (LastError() == SOCKET_EINTR)
            return -4;

        else if (LastError() == SOCKET_EPIPE)
            return -5;

        else
            return -1;
    }
 
    return sent;
}
开发者ID:StephenMacras,项目名称:dsl-n55u-bender,代码行数:36,代码来源:cyassl_io.c

示例2: GetStdHandle

result_t console_base::clear()
{
    HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordScreen = { 0, 0 };
    DWORD cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    DWORD dwConSize;

    if (!GetConsoleScreenBufferInfo(hd, &csbi))
        return CHECK_ERROR(LastError());

    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

    FillConsoleOutputCharacter(hd, ' ', dwConSize,
                               coordScreen, &cCharsWritten);

    if (!GetConsoleScreenBufferInfo(hd, &csbi))
        return CHECK_ERROR(LastError());

    FillConsoleOutputAttribute(hd, csbi.wAttributes, dwConSize,
                               coordScreen, &cCharsWritten);

    SetConsoleCursorPosition(hd, coordScreen);
    return 0;
}
开发者ID:ngot,项目名称:fibjs,代码行数:25,代码来源:console.cpp

示例3: CHECK_ERROR

result_t os_base::networkInfo(v8::Local<v8::Object> &retVal)
{
    unsigned long size = 0;
    IP_ADAPTER_ADDRESSES *adapter_addresses;
    IP_ADAPTER_ADDRESSES *adapter_address;
    IP_ADAPTER_UNICAST_ADDRESS_XP *unicast_address;

    if (GetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &size)
            != ERROR_BUFFER_OVERFLOW)
        return CHECK_ERROR(LastError());

    adapter_addresses = (IP_ADAPTER_ADDRESSES *) malloc(size);
    if (!adapter_addresses)
        return CHECK_ERROR(LastError());

    if (GetAdaptersAddresses(AF_UNSPEC, 0, NULL, adapter_addresses, &size)
            != ERROR_SUCCESS)
        return CHECK_ERROR(LastError());

    retVal = v8::Object::New(isolate);

    for (adapter_address = adapter_addresses; adapter_address != NULL;
            adapter_address = adapter_address->Next)
    {
        v8::Local<v8::Array> ret;
        v8::Local<v8::Object> o;
        v8::Local<v8::String> name, ipaddr, family;

        if (adapter_address->OperStatus != IfOperStatusUp)
            continue;

        name = v8::String::NewFromUtf8(isolate, UTF8_A(adapter_address->FriendlyName));

        ret = v8::Array::New(isolate);
        retVal->Set(name, ret);

        unicast_address =
            (IP_ADAPTER_UNICAST_ADDRESS_XP *) adapter_address->FirstUnicastAddress;
        while (unicast_address)
        {
            inetAddr *sock_addr = (inetAddr *) unicast_address->Address.lpSockaddr;

            o = v8::Object::New(isolate);
            o->Set(v8::String::NewFromUtf8(isolate, "address"), v8::String::NewFromUtf8(isolate, sock_addr->str().c_str()));
            o->Set(v8::String::NewFromUtf8(isolate, "family"), sock_addr->family() == net_base::_AF_INET6 ?
                   v8::String::NewFromUtf8(isolate, "IPv6") : v8::String::NewFromUtf8(isolate, "IPv4"));
            o->Set(v8::String::NewFromUtf8(isolate, "internal"),
                   adapter_address->IfType == IF_TYPE_SOFTWARE_LOOPBACK ?
                   v8::True(isolate) : v8::False(isolate));

            ret->Set(ret->Length(), o);

            unicast_address = unicast_address->Next;
        }
    }

    free(adapter_addresses);

    return 0;
}
开发者ID:CYCOK,项目名称:fibjs,代码行数:60,代码来源:os_win.cpp

示例4: create_name_pipe

result_t create_name_pipe(HANDLE* hd1, HANDLE* hd2, bool in)
{
	HANDLE hMine, hChild;
	char fname[128];

	do
	{
		sprintf(fname, "\\\\.\\pipe\\fibs.namedpipe.%d", rand());
		hMine = CreateNamedPipe(fname, (in ? PIPE_ACCESS_OUTBOUND : PIPE_ACCESS_INBOUND) | FILE_FLAG_OVERLAPPED,
		                        PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
		                        1, 4096, 4096, 0, NULL);
	} while ((hMine == INVALID_HANDLE_VALUE) && (GetLastError() == ERROR_PIPE_BUSY));
	if (hMine == INVALID_HANDLE_VALUE)
		return CHECK_ERROR(LastError());

	SECURITY_ATTRIBUTES sa;
	sa.nLength = sizeof(SECURITY_ATTRIBUTES);
	sa.bInheritHandle = TRUE;
	sa.lpSecurityDescriptor = NULL;

	hChild = CreateFile( fname, in ? GENERIC_READ : GENERIC_WRITE, 0, &sa, OPEN_EXISTING,
	                     FILE_ATTRIBUTE_NORMAL, 0);
	if (hChild == INVALID_HANDLE_VALUE)
	{
		CloseHandle(hMine);
		return CHECK_ERROR(LastError());
	}

	*hd1 = hMine;
	*hd2 = hChild;

	return 0;
}
开发者ID:yeyuguo,项目名称:fibjs,代码行数:33,代码来源:SubProcess_win.cpp

示例5: sysconf

result_t os_base::CPUInfo(v8::Local<v8::Array> &retVal)
{
    retVal = v8::Array::New(isolate);

    v8::Local<v8::Object> cpuinfo;
    v8::Local<v8::Object> cputimes;
    unsigned int ticks = (unsigned int) sysconf(_SC_CLK_TCK), multiplier =
                             ((uint64_t) 1000L / ticks);
    char model[512];
    uint64_t cpuspeed;
    size_t size;

    size = sizeof(model);
    if (sysctlbyname("hw.model", &model, &size, NULL, 0) < 0)
        return CHECK_ERROR(LastError());

    size = sizeof(cpuspeed);
    if (sysctlbyname("hw.cpufrequency", &cpuspeed, &size, NULL, 0) < 0)
        return CHECK_ERROR(LastError());

    natural_t numcpus;
    mach_msg_type_number_t count;
    processor_cpu_load_info_data_t *info;
    if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus,
                            reinterpret_cast<processor_info_array_t *>(&info),
                            &count) != KERN_SUCCESS)
        return CHECK_ERROR(LastError());

    retVal = v8::Array::New(isolate, numcpus);
    for (unsigned int i = 0; i < numcpus; i++)
    {
        cpuinfo = v8::Object::New(isolate);
        cputimes = v8::Object::New(isolate);
        cputimes->Set(v8::String::NewFromUtf8(isolate, "user"),
                      v8::Number::New(isolate, (uint64_t)(info[i].cpu_ticks[0]) * multiplier));
        cputimes->Set(v8::String::NewFromUtf8(isolate, "nice"),
                      v8::Number::New(isolate, (uint64_t)(info[i].cpu_ticks[3]) * multiplier));
        cputimes->Set(v8::String::NewFromUtf8(isolate, "sys"),
                      v8::Number::New(isolate, (uint64_t)(info[i].cpu_ticks[1]) * multiplier));
        cputimes->Set(v8::String::NewFromUtf8(isolate, "idle"),
                      v8::Number::New(isolate, (uint64_t)(info[i].cpu_ticks[2]) * multiplier));
        cputimes->Set(v8::String::NewFromUtf8(isolate, "irq"), v8::Number::New(isolate, 0));

        cpuinfo->Set(v8::String::NewFromUtf8(isolate, "model"), v8::String::NewFromUtf8(isolate, model));
        cpuinfo->Set(v8::String::NewFromUtf8(isolate, "speed"),
                     v8::Number::New(isolate, cpuspeed / 1000000));

        cpuinfo->Set(v8::String::NewFromUtf8(isolate, "times"), cputimes);
        retVal->Set(i, cpuinfo);
    }
    vm_deallocate(mach_task_self(), (vm_address_t) info, count);

    return 0;
}
开发者ID:CYCOK,项目名称:fibjs,代码行数:54,代码来源:os_osx.cpp

示例6: CHECK_ERROR

result_t File::readAll(obj_ptr<Buffer_base> &retVal, AsyncEvent *ac)
{
    if (m_fd == -1)
        return CHECK_ERROR(CALL_E_INVALID_CALL);

    if (!ac)
        return CHECK_ERROR(CALL_E_NOSYNC);

    qstring strBuf;

    int32_t bytes;
    int64_t p = _lseeki64(m_fd, 0, SEEK_CUR);
    if (p < 0)
        return CHECK_ERROR(LastError());

    int64_t sz = _lseeki64(m_fd, 0, SEEK_END);
    if (sz < 0)
        return CHECK_ERROR(LastError());

    if (_lseeki64(m_fd, p, SEEK_SET) < 0)
        return CHECK_ERROR(LastError());

    sz -= p;

    bytes = (int32_t) sz;

    if (bytes > 0)
    {
        strBuf.resize(bytes);
        int32_t sz = bytes;
        char *p = &strBuf[0];

        while (sz)
        {
            int32_t n = (int32_t) ::_read(m_fd, p, sz > STREAM_BUFF_SIZE ? STREAM_BUFF_SIZE : sz);
            if (n < 0)
                return CHECK_ERROR(LastError());
            if (n == 0)
                break;

            sz -= n;
            p += n;
        }

        strBuf.resize(bytes - sz);
    }

    if (strBuf.length() == 0)
        return CALL_RETURN_NULL;

    retVal = new Buffer(strBuf);

    return 0;
}
开发者ID:zhangyinglong,项目名称:fibjs,代码行数:54,代码来源:File.cpp

示例7: CHECK_ERROR

result_t fs_base::read(int32_t fd, Buffer_base* buffer, int32_t offset, int32_t length,
    int32_t position, int32_t& retVal, AsyncEvent* ac)
{
    if (fd < 0)
        return CHECK_ERROR(CALL_E_INVALID_CALL);

    if (ac->isSync())
        return CHECK_ERROR(CALL_E_NOSYNC);

    int32_t bufLength;
    buffer->get_length(bufLength);

    if (offset < 0 || offset >= bufLength)
        return Runtime::setError("Offset is out of bounds");

    exlib::string strBuf;

    if (length < 0 || (offset + length > bufLength)) {
        return Runtime::setError("Length extends beyond buffer");
    }

    if (position > -1) {
        if (_lseeki64(fd, position, SEEK_SET) < 0)
            return CHECK_ERROR(LastError());
    }

    if (length > 0) {
        strBuf.resize(length);
        int32_t sz = length;
        char* p = &strBuf[0];

        while (sz) {
            int32_t n = (int32_t)::_read(fd, p, sz > STREAM_BUFF_SIZE ? STREAM_BUFF_SIZE : sz);
            if (n < 0)
                return CHECK_ERROR(LastError());
            if (n == 0)
                break;

            sz -= n;
            p += n;
        }

        strBuf.resize(length - sz);
    }

    if (strBuf.length() == 0) {
        retVal = 0;
        return 0;
    }

    return buffer->write(strBuf, offset, (int32_t)strBuf.length(), "utf8", retVal);
}
开发者ID:asionius,项目名称:fibjs,代码行数:52,代码来源:fs.cpp

示例8: CopyOut

exp bool CopyOut(const char* source, const char* dest) {
    // Convert the filename into DOS8.3 format
    char* dosName = new char[12];
    ToDos83Name(source, dosName);

    // Find the file on the disk
    DirectoryEntry* entry = FindEntry(dosName, &directory);
    if (!entry) {
        LastError("CopyOut", "File doesn't exist");
        return false;
    }

    if (!(entry->attrib & ATTRIB_ARCHIVE)) {
        LastError("CopyOut", "This is not a file");
        return false;
    }

    // Update the entry
    UpdateEntry(entry, 0, 0);

    std::ofstream outHandle(dest, std::ios::out | std::ios::binary);
    if (!outHandle.is_open())
        return false;

    // Set up a FatEntry
    FatEntry fatEntry;
    fatEntry.cluster = GetClusterFromEntry(entry);
    fatEntry.sector = GetFATSector(fatEntry.cluster);
    fatEntry.buffer = new char[bpb->bytesPerSector];
    ReadSector(fatEntry.buffer, fatEntry.sector);

    char* sectorData = new char[bpb->bytesPerSector];

    // Read Data
    while (ReadCluster(&fatEntry, sectorData))
        outHandle.write(sectorData, 512);

    if (!(entry->size % bpb->bytesPerSector))
        outHandle.write(sectorData, 512);
    else
        outHandle.write(sectorData, entry->size % bpb->bytesPerSector);

    delete[] fatEntry.buffer;
    delete[] sectorData;
    delete[] dosName;

    outHandle.close();

    return true;
}
开发者ID:Rohansi,项目名称:LoonyOS,代码行数:50,代码来源:main.cpp

示例9: LogMessage

int CRealControlSocket::ContinueConnect(const wxIPV4address *address)
{
	LogMessage(__TFILE__, __LINE__, this, Debug_Verbose, _T("CRealControlSocket::ContinueConnect(%p) m_pEngine=%p"), address, m_pEngine);
	if (GetCurrentCommandId() != cmd_connect ||
		!m_pCurrentServer)
	{
		LogMessage(Debug_Warning, _T("Invalid context for call to ContinueConnect(), cmd=%d, m_pCurrentServer=%p"), GetCurrentCommandId(), m_pCurrentServer);
		return DoClose(FZ_REPLY_INTERNALERROR);
	}
	
	if (!address)
	{
		LogMessage(::Error, _("Invalid hostname or host not found"));
		return DoClose(FZ_REPLY_ERROR | FZ_REPLY_CRITICALERROR);
	}

	CConnectOpData* pData;
	if (!m_pCurOpData || m_pCurOpData->opId != cmd_connect)
		pData = 0;
	else
		pData = static_cast<CConnectOpData *>(m_pCurOpData);

	const unsigned int port = pData ? pData->port : m_pCurrentServer->GetPort();
	LogMessage(Status, _("Connecting to %s:%d..."), address->IPAddress().c_str(), port);

	wxIPV4address addr = *address;
	addr.Service(port);

	bool res = wxSocketClient::Connect(addr, false);

	if (!res && LastError() != wxSOCKET_WOULDBLOCK)
		return DoClose();

	return FZ_REPLY_WOULDBLOCK;
}
开发者ID:idgaf,项目名称:FileZilla3,代码行数:35,代码来源:ControlSocket.cpp

示例10: utf8to16String

result_t path_base::fullpath(exlib::string path, exlib::string &retVal)
{
#ifdef _WIN32
    exlib::wstring str = utf8to16String(path);
    exlib::wchar utf16_buffer[MAX_PATH];

    DWORD utf16_len = GetFullPathNameW(str.c_str(), MAX_PATH, utf16_buffer, NULL);
    if (!utf16_len)
        return CHECK_ERROR(LastError());

    retVal = utf16to8String(utf16_buffer, (int32_t)utf16_len);
    return 0;
#else
    if (isPathSlash(path.c_str()[0]))
        return normalize(path, retVal);

    exlib::string str;

    process_base::cwd(str);
    str.append(1, PATH_SLASH);
    str.append(path);

    return normalize(str, retVal);
#endif
}
开发者ID:anlebcoder,项目名称:fibjs,代码行数:25,代码来源:path.cpp

示例11: CHECK_ERROR

result_t os_base::memoryUsage(v8::Local<v8::Object> &retVal)
{
    size_t rss = 0;

    struct task_basic_info t_info;
    mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;

    if (task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t) &t_info,
                  &t_info_count) != KERN_SUCCESS)
        return CHECK_ERROR(LastError());

    rss = t_info.resident_size;

    v8::Local<v8::Object> info = v8::Object::New(isolate);

    v8::HeapStatistics v8_heap_stats;
    isolate->GetHeapStatistics(&v8_heap_stats);
    info->Set(v8::String::NewFromUtf8(isolate, "rss"), v8::Integer::New(isolate, (int32_t)rss));
    info->Set(v8::String::NewFromUtf8(isolate, "heapTotal"),
              v8::Integer::New(isolate, (int32_t)v8_heap_stats.total_heap_size()));
    info->Set(v8::String::NewFromUtf8(isolate, "heapUsed"),
              v8::Integer::New(isolate, (int32_t)v8_heap_stats.used_heap_size()));
    info->Set(v8::String::NewFromUtf8(isolate, "nativeObjects"),
              v8::Integer::New(isolate, (int32_t)g_obj_refs));

    retVal = info;

    return 0;
}
开发者ID:CYCOK,项目名称:fibjs,代码行数:29,代码来源:os_osx.cpp

示例12: Exception

void PEFile::Dump(LPCTSTR filename)
{
    FileMapping mapping;
    if (!mapping.Create(filename, GENERIC_READ, FILE_SHARE_READ,
                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, PAGE_READONLY)) {
        throw Exception(LastError());
    }

    LPVOID pBase;
    if ((pBase = mapping.MapView(FILE_MAP_READ, 0, 0)) == NULL) {
        throw Exception(_T("Unable to map view of file."));
    }

    PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)pBase;
    PIMAGE_FILE_HEADER pImgFileHdr = (PIMAGE_FILE_HEADER)pBase;

    if (pDosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
        throw Exception(_T(".EXE format not supported."));
    } else if (PECommon::IsValidMachineType(pImgFileHdr->Machine)) {
        if (pImgFileHdr->SizeOfOptionalHeader == 0)	{	// 0 optional header
            ObjectFile::Dump(pImgFileHdr);				// means it's an OBJ
        } else {
            throw Exception(_T("Unrecognized file format."));
        }
    } else if (memcmp(pBase, IMAGE_ARCHIVE_START,
                      IMAGE_ARCHIVE_START_SIZE) == 0) {
        LibraryFile archive;
        archive.Dump(pBase);
    } else {
        throw Exception(_T("Unrecognized file format."));
    }
}
开发者ID:trieck,项目名称:source,代码行数:32,代码来源:pefile.cpp

示例13: DirCreate

exp bool DirCreate(const char* dirName) {
    // Convert the filename into DOS8.3 format
    char* dosName = new char[12];
    ToDos83Name(dirName, dosName);

    DirectoryEntry* entry = MakeEntry(dosName, ATTRIB_DIRECTORY, 0, &directory);
    if (!entry) {
        LastError("DirCreate", "Failed to create a directory");
        delete[] dosName;
        return false;
    }

    // Write FAT entry
    FatEntry fatEntry;
    fatEntry.buffer = new char[bpb->bytesPerSector];
    fatEntry.cluster = GetClusterFromEntry(entry);
    fatEntry.sector = GetFATSector(fatEntry.cluster);

    UpdateFAT(&fatEntry, GetClusterFromEntry(entry));

    // Write entry to disk
    DirectoryWrite(&directory);
    //WriteSector(directoryBuffer + ((((char*)entry - directoryBuffer) / 512) * 512),directorySector + (((char*)entry - directoryBuffer) / 512));

    delete[] dosName;
    delete[] fatEntry.buffer;

    return true;
}
开发者ID:Rohansi,项目名称:LoonyOS,代码行数:29,代码来源:main.cpp

示例14: sizeof

result_t os_base::get_execPath(std::string &retVal)
{
    char exeName[1024] = "";
    size_t size = sizeof(exeName);

    int32_t mib[4];

#ifdef __DragonFly__
    mib[0] = CTL_KERN;
    mib[1] = KERN_PROC;
    mib[2] = KERN_PROC_ARGS;
    mib[3] = getpid();
#else
    mib[0] = CTL_KERN;
    mib[1] = KERN_PROC;
    mib[2] = KERN_PROC_PATHNAME;
    mib[3] = -1;
#endif

    if (sysctl(mib, 4, exeName, &size, NULL, 0) < 0)
        return CHECK_ERROR(LastError());

    retVal = exeName;
    return 0;
}
开发者ID:540513310,项目名称:fibjs,代码行数:25,代码来源:os_freebsd.cpp

示例15: fopen

result_t os_base::CPUs(int32_t &retVal)
{
    static int cpus = 0;

    if (cpus > 0)
    {
        retVal = cpus;
        return 0;
    }

    int numcpus = 0;
    char line[512];
    FILE *fpModel = fopen("/proc/cpuinfo", "r");

    if (fpModel)
    {
        while (fgets(line, 511, fpModel) != NULL)
            if (strncmp(line, "processor", 9) == 0)
                numcpus++;
        fclose(fpModel);

        retVal = cpus = numcpus;
    }
    else
        return CHECK_ERROR(LastError());

    return 0;
}
开发者ID:Andrew-Zhang,项目名称:fibjs,代码行数:28,代码来源:os_linux.cpp


注:本文中的LastError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。