Refactoring BIO: reimplement old socket handling functions with new ones