Exemplo n.º 1
0
void adaptive_sort( RandIt first, RandIt last, Compare comp
               , RandRawIt uninitialized
               , std::size_t uninitialized_len)
{
   typedef typename iterator_traits<RandIt>::size_type  size_type;
   typedef typename iterator_traits<RandIt>::value_type value_type;

   ::boost::movelib::detail_adaptive::adaptive_xbuf<value_type, RandRawIt> xbuf(uninitialized, uninitialized_len);
   ::boost::movelib::detail_adaptive::adaptive_sort_impl(first, size_type(last - first), comp, xbuf);
}
void adaptive_merge( RandIt first, RandIt middle, RandIt last, Compare comp
                , typename iterator_traits<RandIt>::value_type* uninitialized = 0
                , std::size_t uninitialized_len = 0)
{
   typedef typename iterator_traits<RandIt>::size_type  size_type;
   typedef typename iterator_traits<RandIt>::value_type value_type;

   ::boost::movelib::detail_adaptive::adaptive_xbuf<value_type> xbuf(uninitialized, uninitialized_len);
   ::boost::movelib::detail_adaptive::adaptive_merge_impl(first, size_type(middle - first), size_type(last - middle), comp, xbuf);
}
Exemplo n.º 3
0
bool WriteFile(HANDLE hFile, LPCVOID buffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, void* dummyforAPI)
{
    int written_len = 0;
    //usleep(3000);
    fd_set writefd;
    //int state;

    struct timeval timeout;
   // timeout.tv_sec = 0;
   // timeout.tv_usec = 500000;
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;

    bool is_written = false;

    LPCVOID obuf = buffer;
    DWORD onum = nNumberOfBytesToWrite;

    //LOG("%d, %p, %d, %p\n", hFile, buffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten);
    while(!is_written)
    {
        FD_ZERO(&writefd);
        FD_SET(hFile, &writefd);
        if( select(hFile+1, NULL , &writefd, NULL, &timeout) > 0)
        {
            //int ifd;
            //for(ifd=0; ifd < hFile+1; ifd++)
            {
                if (FD_ISSET(hFile, &writefd))
                {
                    //if(ifd == hFile)
                    {
/*#define PSIZ 64*/
                        //printf("To  ttyACM0 write data....\n");
                        ssize_t wlen = write(hFile, buffer, (size_t)nNumberOfBytesToWrite > PSIZ ? PSIZ : (size_t)nNumberOfBytesToWrite);
                        /*printf("%d written\n", written_len);
                        {
                            int i = 0;
                            while(i < written_len)
                            {
                                printf("%x ",((const char*)buffer)[i++]);
                            }
                            printf("\n");
                        }*/
                        if (wlen > 0) {
                            nNumberOfBytesToWrite -= wlen;
                            buffer += wlen;
                            written_len += wlen;
                        }
                        if (nNumberOfBytesToWrite == 0 || wlen <= 0) {
                            is_written = true;
                            char buf[BUFSIZ] = "";
                            LOG("fd %d W %d/%u >>> %s\n", hFile, written_len, onum, xbuf(buf, obuf, onum));
                        }
                    }
                }
            }
       }
        else
       {
            printf("write timeout\n");
            break;
       }
    }

    if(written_len >= 0)
    {
        if(lpNumberOfBytesWritten != NULL)
        {
            *lpNumberOfBytesWritten = written_len;
        }
        return true;
    }
    else
    {
        if(lpNumberOfBytesWritten != NULL)
        {
            *lpNumberOfBytesWritten = 0;
        }
        return false;
    }
}
Exemplo n.º 4
0
bool ReadFile(HANDLE hFile, LPVOID buffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, void* dummyforAPI)
{
    int read_len = 0;

    //usleep(3000);
    fd_set    readfd;
    struct timeval timeout;
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;
    bool is_read = false;
    while(!is_read)
    {
        FD_ZERO(&readfd);
        FD_SET(hFile, &readfd);
        if( select(hFile+1, &readfd , NULL, NULL, &timeout) > 0)
        {
            //int ifd;
            //for(ifd=0; ifd < hFile+1; ifd++)
            {
                if (FD_ISSET(hFile, &readfd))
                {
                    //if(ifd == hFile)
                    {
                        //printf("Read from ttyACM0...\n");
                        read_len = read(hFile, buffer, nNumberOfBytesToRead);
                        char buf[BUFSIZ] = "";
                        LOG("fd %d R %d/%u  <<< %s\n", hFile, read_len, nNumberOfBytesToRead, xbuf(buf, buffer, read_len));
                        is_read = true;
                        /*{
                            int i = 0;
                            while(i < read_len)
                            {
                                printf("%x ",((const char*)buffer)[i++]);
                            }
                            printf("\n");
                        }*/
                    }
                }
            }
        }
        else
        {
            printf("read timeout 5s? %p\n", __builtin_return_address(0));
            break;
        }
    }

    if(read_len >= 0)
    {
        if(lpNumberOfBytesRead != NULL)
        {
            *lpNumberOfBytesRead = read_len;
        }
        return true;
    }
    else
    {
        if(lpNumberOfBytesRead != NULL)
        {
            *lpNumberOfBytesRead = 0;
        }
        return false;
    }
}