Use 'send()' or 'sendto()' depending on whether or not the socket is
already connected to a remote address
This commit is contained in:
		
							
								
								
									
										8
									
								
								sock.cpp
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								sock.cpp
									
									
									
									
									
								
							@@ -55,7 +55,13 @@ void Sock::sendAll(std::string to_send) {
 | 
			
		||||
 | 
			
		||||
	/* For UDP sockets */
 | 
			
		||||
	if (this->protocol == ES_UDP) {
 | 
			
		||||
		if (sendto(this->sock_fd, to_send.data(), str_length, 0, (struct sockaddr *)dest, addrlen) == -1) {
 | 
			
		||||
	    int retval;
 | 
			
		||||
		if (this->has_remote_address()) {
 | 
			
		||||
            retval = send(this->sock_fd, to_send.data(), str_length, 0);
 | 
			
		||||
        } else {
 | 
			
		||||
            retval = sendto(this->sock_fd, to_send.data(), str_length, 0, (struct sockaddr *)dest, addrlen);
 | 
			
		||||
        }
 | 
			
		||||
        if (retval == -1) {
 | 
			
		||||
			throw errno;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user