static void print_socket_line(net_socket_private* socket, const char* prefix) { BReference<net_socket_private> parent = socket->parent.GetReference(); kprintf("%s%p %2d.%2d.%2d %6ld %p %p %p%s\n", prefix, socket, socket->family, socket->type, socket->protocol, socket->owner, socket->first_protocol, socket->first_info, parent.Get(), parent.Get() != NULL ? socket->is_connected ? " (c)" : " (p)" : ""); }
status_t BNetworkAddress::SetTo(int family, const char* host, const char* service, uint32 flags) { if (family == AF_LINK) { if (service != NULL) return B_BAD_VALUE; return _ParseLinkAddress(host); // SetToLinkAddress takes care of setting fStatus } BReference<const BNetworkAddressResolver> resolver = BNetworkAddressResolver::Resolve(family, host, service, flags); if (resolver.Get() == NULL) return B_NO_MEMORY; status_t status = resolver->InitCheck(); if (status != B_OK) return status; uint32 cookie = 0; status = resolver->GetNextAddress(&cookie, *this); if (status != B_OK) Unset(); fHostName = host; fStatus = status; return status; }
status_t BNetworkAddress::SetTo(const char* host, const char* service, uint32 flags) { BReference<const BNetworkAddressResolver> resolver = BNetworkAddressResolver::Resolve(host, service, flags); if (resolver.Get() == NULL) return B_NO_MEMORY; status_t status = resolver->InitCheck(); if (status != B_OK) return status; // Prefer IPv6 addresses uint32 cookie = 0; status = resolver->GetNextAddress(AF_INET6, &cookie, *this); if (status != B_OK) { cookie = 0; status = resolver->GetNextAddress(&cookie, *this); if (status != B_OK) Unset(); } fHostName = host; fStatus = status; return status; }
bool SATGroup::RemoveWindow(SATWindow* window, bool stayBelowMouse) { if (!fSATWindowList.RemoveItem(window)) return false; // We need the area a little bit longer because the area could hold the // last reference to the group. BReference<WindowArea> area = window->GetWindowArea(); if (area.Get() != NULL) area->_RemoveWindow(window); window->RemovedFromGroup(this, stayBelowMouse); if (CountItems() >= 2) WindowAt(0)->DoGroupLayout(); return true; }
static int dump_socket(int argc, char** argv) { if (argc < 2) { kprintf("usage: %s [address]\n", argv[0]); return 0; } net_socket_private* socket = (net_socket_private*)parse_expression(argv[1]); kprintf("SOCKET %p\n", socket); kprintf(" family.type.protocol: %d.%d.%d\n", socket->family, socket->type, socket->protocol); BReference<net_socket_private> parent = socket->parent.GetReference(); kprintf(" parent: %p\n", parent.Get()); kprintf(" first protocol: %p\n", socket->first_protocol); kprintf(" first module_info: %p\n", socket->first_info); kprintf(" options: %x\n", socket->options); kprintf(" linger: %d\n", socket->linger); kprintf(" bound to device: %" B_PRIu32 "\n", socket->bound_to_device); kprintf(" owner: %ld\n", socket->owner); kprintf(" max backlog: %ld\n", socket->max_backlog); kprintf(" is connected: %d\n", socket->is_connected); kprintf(" child_count: %lu\n", socket->child_count); if (socket->child_count == 0) return 0; kprintf(" pending children:\n"); SocketList::Iterator iterator = socket->pending_children.GetIterator(); while (net_socket_private* child = iterator.Next()) { print_socket_line(child, " "); } kprintf(" connected children:\n"); iterator = socket->connected_children.GetIterator(); while (net_socket_private* child = iterator.Next()) { print_socket_line(child, " "); } return 0; }
status_t BNetworkAddress::SetTo(int family, const char* host, uint16 port, uint32 flags) { if (family == AF_LINK) { if (port != 0) return B_BAD_VALUE; return _ParseLinkAddress(host); } BReference<const BNetworkAddressResolver> resolver = BNetworkAddressResolver::Resolve(family, host, port, flags); if (resolver.Get() == NULL) return B_NO_MEMORY; status_t status = resolver->InitCheck(); if (status != B_OK) return status; uint32 cookie = 0; return resolver->GetNextAddress(&cookie, *this); }
status_t BNetworkAddress::SetTo(const char* host, uint16 port, uint32 flags) { BReference<const BNetworkAddressResolver> resolver = BNetworkAddressResolver::Resolve(host, port, flags); if (resolver.Get() == NULL) return B_NO_MEMORY; status_t status = resolver->InitCheck(); if (status != B_OK) return status; // Prefer IPv6 addresses uint32 cookie = 0; status = resolver->GetNextAddress(AF_INET6, &cookie, *this); if (status == B_OK) return B_OK; cookie = 0; return resolver->GetNextAddress(&cookie, *this); }
/*! The socket has been aborted. Steals the parent's reference, and releases it. */ status_t socket_aborted(net_socket* _socket) { net_socket_private* socket = (net_socket_private*)_socket; TRACE("socket_aborted(%p)\n", socket); BReference<net_socket_private> parent = socket->parent.GetReference(); if (parent.Get() == NULL) return B_BAD_VALUE; MutexLocker _(parent->lock); if (socket->is_connected) parent->connected_children.Remove(socket); else parent->pending_children.Remove(socket); parent->child_count--; socket->RemoveFromParent(); return B_OK; }
/*! The socket has been connected. It will be moved to the connected queue of its parent socket. */ status_t socket_connected(net_socket* _socket) { net_socket_private* socket = (net_socket_private*)_socket; TRACE("socket_connected(%p)\n", socket); BReference<net_socket_private> parent = socket->parent.GetReference(); if (parent.Get() == NULL) return B_BAD_VALUE; MutexLocker _(parent->lock); parent->pending_children.Remove(socket); parent->connected_children.Add(socket); socket->is_connected = true; // notify parent if (parent->select_pool) notify_select_event_pool(parent->select_pool, B_SELECT_READ); return B_OK; }