int bufferevent_async_connect_(struct bufferevent *bev, evutil_socket_t fd, const struct sockaddr *sa, int socklen) { BOOL rc; struct bufferevent_async *bev_async = upcast(bev); struct sockaddr_storage ss; const struct win32_extension_fns *ext = event_get_win32_extension_fns_(); EVUTIL_ASSERT(ext && ext->ConnectEx && fd >= 0 && sa != NULL); /* ConnectEx() requires that the socket be bound to an address * with bind() before using, otherwise it will fail. We attempt * to issue a bind() here, taking into account that the error * code is set to WSAEINVAL when the socket is already bound. */ memset(&ss, 0, sizeof(ss)); if (sa->sa_family == AF_INET) { struct sockaddr_in *sin = (struct sockaddr_in *)&ss; sin->sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_ANY; } else if (sa->sa_family == AF_INET6) { struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ss; sin6->sin6_family = AF_INET6; sin6->sin6_addr = in6addr_any; } else { /* Well, the user will have to bind() */ return -1; } if (bind(fd, (struct sockaddr *)&ss, sizeof(ss)) < 0 && WSAGetLastError() != WSAEINVAL) return -1; event_base_add_virtual_(bev->ev_base); bufferevent_incref_(bev); rc = ext->ConnectEx(fd, sa, socklen, NULL, 0, NULL, &bev_async->connect_overlapped.overlapped); if (rc || WSAGetLastError() == ERROR_IO_PENDING) return 0; event_base_del_virtual_(bev->ev_base); bufferevent_decref_(bev); return -1; }
static void be_async_inbuf_callback(struct evbuffer *buf, const struct evbuffer_cb_info *cbinfo, void *arg) { struct bufferevent *bev = arg; struct bufferevent_async *bev_async = upcast(bev); /* If we drained data from the inbuf and were not reading before, * we may want to read now */ _bufferevent_incref_and_lock(bev); if (cbinfo->n_deleted) bev_async_consider_reading(bev_async); _bufferevent_decref_and_unlock(bev); }
static void be_async_outbuf_callback(struct evbuffer *buf, const struct evbuffer_cb_info *cbinfo, void *arg) { struct bufferevent *bev = arg; struct bufferevent_async *bev_async = upcast(bev); /* If we added data to the outbuf and were not writing before, * we may want to write now. */ _bufferevent_incref_and_lock(bev); if (cbinfo->n_added) bev_async_consider_writing(bev_async); _bufferevent_decref_and_unlock(bev); }
static int be_async_disable(struct bufferevent *bev, short what) { struct bufferevent_async *bev_async = upcast(bev); /* XXXX If we disable reading or writing, we may want to consider * canceling any in-progress read or write operation, though it might * not work. */ if (what & EV_READ) { BEV_DEL_GENERIC_READ_TIMEOUT(bev); bev_async_del_read(bev_async); } if (what & EV_WRITE) { BEV_DEL_GENERIC_WRITE_TIMEOUT(bev); bev_async_del_write(bev_async); } return 0; }
static int be_async_enable(struct bufferevent *buf, short what) { struct bufferevent_async *bev_async = upcast(buf); if (!bev_async->ok) return -1; /* NOTE: This interferes with non-blocking connect */ if (what & EV_READ) BEV_RESET_GENERIC_READ_TIMEOUT(buf); if (what & EV_WRITE) BEV_RESET_GENERIC_WRITE_TIMEOUT(buf); /* If we newly enable reading or writing, and we aren't reading or writing already, consider launching a new read or write. */ if (what & EV_READ) bev_async_consider_reading(bev_async); if (what & EV_WRITE) bev_async_consider_writing(bev_async); return 0; }
static int be_async_ctrl(struct bufferevent *bev, enum bufferevent_ctrl_op op, union bufferevent_ctrl_data *data) { switch (op) { case BEV_CTRL_GET_FD: data->fd = evbuffer_overlapped_get_fd_(bev->input); return 0; case BEV_CTRL_SET_FD: { struct event_iocp_port *iocp; if (data->fd == evbuffer_overlapped_get_fd_(bev->input)) return 0; if (!(iocp = event_base_get_iocp_(bev->ev_base))) return -1; if (event_iocp_port_associate_(iocp, data->fd, 1) < 0) return -1; evbuffer_overlapped_set_fd_(bev->input, data->fd); evbuffer_overlapped_set_fd_(bev->output, data->fd); return 0; } case BEV_CTRL_CANCEL_ALL: { struct bufferevent_async *bev_a = upcast(bev); evutil_socket_t fd = evbuffer_overlapped_get_fd_(bev->input); if (fd != (evutil_socket_t)INVALID_SOCKET && (bev_a->bev.options & BEV_OPT_CLOSE_ON_FREE)) { closesocket(fd); evbuffer_overlapped_set_fd_(bev->input, INVALID_SOCKET); } bev_a->ok = 0; return 0; } case BEV_CTRL_GET_UNDERLYING: default: return -1; } }
float exposure(const Camera& c) noexcept { const FCamera& camera = upcast(c); return exposure(camera.getAperture(), camera.getShutterSpeed(), camera.getSensitivity()); }
static EXTENDERptr get_active_instance() { return upcast(_active); }
INLINE const value_type *front() const { return upcast(m_root.next); }
INLINE value_type *back() { return upcast(m_root.prev); }
/** * @brief Update an Object in the Database * @param[in] Domain Object * @throws dbapi_error on Database Error */ void update(typename D::Ptr o) { return AbstractMapper::update(upcast(o)); }
const_iterator rbegin() const { return const_iterator(upcast(m_root.prev)); }
const_iterator begin() const { return const_iterator(upcast(m_root.next)); }
iterator rend() { return iterator(upcast(&m_root)); }
iterator rbegin() { return iterator(upcast(m_root.prev)); }
iterator begin() { return iterator(upcast(m_root.next)); }
INLINE const value_type *back() const { return upcast(m_root.prev); }
/** * @brief Insert an Object into the Database * @param[in] Domain Object * @return Inserted RowId */ int64_t insert(typename D::Ptr o) { return AbstractMapper::insert(upcast(o)); }
const_iterator rend() const { return const_iterator(upcast(&m_root)); }
/** * @brief Remove an Object from the Database * @param[in] Domain Object * @throws dbapi_error on Database Error */ void remove(typename D::Ptr o) { return AbstractMapper::remove(upcast(o)); }
static GLfloat raycast_stars(const std::vector<star_t>& nebula_stars, volume<glm::vec3, X, Y, Z>& light_volume, const volume<glm::vec4, X, Y, Z>& dust_volume) { static constexpr GLfloat occlusion = 0.005; static constexpr GLfloat stepsize = 0.001; static constexpr GLfloat falloff = 1.2; GLfloat max_intensity = 0.0; for(size_t x = 0; x < X; ++x) for(size_t y = 0; y < Y; ++y) for(size_t z = 0; z < Z; ++z) { glm::uvec3 pos(x, y, z); glm::vec3 fpos = downcast(pos, fX, fY, fZ); glm::vec3 color = glm::vec3(0.0); GLfloat total_intensity = 0.0; for(const star_t& star : nebula_stars) { glm::vec3 dir = fpos - star.pos; GLfloat len = glm::length(dir); if(len == 0.0) continue; glm::vec3 norm_dir = glm::normalize(dir); glm::vec3 delta_dir = norm_dir * stepsize; GLfloat delta_dir_len = glm::length(delta_dir); glm::vec3 vec = star.pos; size_t step_count = len / delta_dir_len - 1; GLfloat intensity = 1.0; for(size_t i = 0; i < step_count; ++i) { glm::uvec3 uvec = upcast(vec, fX, fY, fZ); intensity -= dust_volume[uvec].a * occlusion * stepsize; vec += delta_dir; if(intensity <= 0.0) break; } intensity *= 1.0f - std::pow(len*falloff, 2.0f); if(intensity > 0.0) // If not completely occluded { color += star.color * intensity; total_intensity += intensity; } } light_volume[pos] = color; max_intensity = glm::max(max_intensity, total_intensity); } return max_intensity; }
INLINE value_type *front() { return upcast(m_root.next); }