Exemplo n.º 1
0
int EPoll::wait(float timeout)
{
    int millisec = (-1);

    TRY_EXCEPTIONS;

    if(m_epfd < 0 || !m_epev)
    {
        THROW_EXCEPTIONS("epoll descriptor has not been created yet. epfd(%d) epev(%p)", m_epfd, m_epev);
    }

    if(timeout >= 0.0)
        millisec = (int)(timeout * 1000.0);

    m_epsz = epoll_wait(m_epfd, m_epev, m_epmaxsz, millisec);

    if(m_epsz < 0)
    {
        if(errno != EINTR)
        {
            THROW_ERRORS(errno, "epoll_wait(%d, %p, %d, %d) failed.", m_epfd, m_epev, m_epsz, millisec);
        }
    }

    CATCH_EXCEPTIONS(-1);

    return m_epsz;
}
Exemplo n.º 2
0
/* Read all of the DICOM files from a directory into an Image struct. Slices 
 * must be ordered alphanumerically, starting with z = 0. */
int read_dcm_dir(const char *path, Image *const im) {

        int ret;

        CATCH_EXCEPTIONS(ret, "read_dcm_dir", read_dcm_dir_cpp, path, im);

        return ret;
}
Exemplo n.º 3
0
bool EPoll::create(int size, bool cloexec)
{
    TRY_EXCEPTIONS;

    if(m_epfd >= 0 || m_epev)
    {
        THROW_EXCEPTIONS("epoll descriptor is already created.");
    }

    if(size <= 0)
    {
        THROW_EXCEPTIONS("invalid backing store size.");
    }

    if((m_epfd = epoll_create(size)) < 0)
    {
        THROW_ERRORS(errno, "epoll_create() failed.");
    }

    m_epev = new(std::nothrow) epoll_event[size];
    
    if(!m_epev)
    {
        EPoll::close();
        THROW_EXCEPTIONS("insufficient memory.");
    }

    m_epmaxsz = size;

    if(cloexec)
    {
        m_cloexec = true;

        int val = fcntl(m_epfd, F_GETFD, 0);

        if(val < 0)
        {
            EPoll::close();
            THROW_ERRORS(errno, "fcntl(F_GETFL) failed.");
        }

        if(fcntl(m_epfd, F_SETFD, val | FD_CLOEXEC) < 0)
        {
            EPoll::close();
            THROW_ERRORS(errno, "fcntl(F_SETFL) failed.");
        }

    }
    else
    {
        m_cloexec = false;
    }

    CATCH_EXCEPTIONS(false);

    return true;
}
Exemplo n.º 4
0
/* Write an Image struct into a directory of DICOM files.
 * Inputs: 
 *      path - File name
 *      im - Image data
 *      meta - Dicom metadata (or NULL for default values)
 *
 * Returns SIFT3D_SUCCESS on success, SIFT3D_FAILURE otherwise.
 */
int write_dcm_dir(const char *path, const Image *const im, 
        const Dcm_meta *const meta) {

        int ret;

        CATCH_EXCEPTIONS(ret, "write_dcm_dir", write_dcm_dir_cpp, path, im, 
                meta);

        return ret;
}
Exemplo n.º 5
0
/* Write an Image struct into a DICOM file. 
 * Inputs: 
 *      path - File name
 *      im - Image data
 *      meta - Dicom metadata (or NULL for default values)
 *      max_val - The maximum value of the image, used for scaling. If set
 *              to a negative number, this functions computes the maximum value
 *              from this image.
 *
 * Returns SIFT3D_SUCCESS on success, SIFT3D_FAILURE otherwise.
 */
int write_dcm(const char *path, const Image *const im, 
        const Dcm_meta *const meta, const float max_val) {

        int ret;

        CATCH_EXCEPTIONS(ret, "write_dcm", write_dcm_cpp, path, im, meta, 
                max_val);

        return ret;
}
Exemplo n.º 6
0
bool EPoll::control(int op, int fd, struct epoll_event* ev)
{
    TRY_EXCEPTIONS;

    if(m_epfd < 0)
    {
        THROW_EXCEPTIONS("epoll descriptor has not been created yet.");
    }

    if(fd < 0)
    {
        THROW_EXCEPTIONS("invalid file descriptor. fd(%d)", fd);
    }

    if(epoll_ctl(m_epfd, op, fd, ev) < 0)
    {
        if(errno == ENOENT)
        {
            if((op & EPOLL_CTL_DEL) || (op & EPOLL_CTL_MOD))
            {
                ERROR("ENOENT, epoll_ctl, epfd(%d) op(%d) fd(%d) ev(%p)", m_epfd, op, fd, ev);
                return false;
            }
        }
        else if(errno == EEXIST)
        {
            if(op & EPOLL_CTL_ADD) 
            {
                ERROR("EEXIST, epoll_ctl, epfd(%d) op(%d) fd(%d) ev(%p)", m_epfd, op, fd, ev);
                return false;
            }
        }

        THROW_ERRORS(errno, "epoll_ctl failed. epfd(%d) op(%d) fd(%d) ev(%p)", m_epfd, op, fd, ev);
    }
    
    CATCH_EXCEPTIONS(false);

    return true;
}