@@ -153,34 +153,22 @@ int manager_push_to_network(Manager *m,
153153 /* Ninth: message */
154154 IOVEC_SET_STRING (iov [n ++ ], message );
155155
156- /* Tenth: Optional newline message separator, if not implicitly terminated by end of UDP frame */
157- if (SYSLOG_TRANSMISSION_PROTOCOL_TCP == m -> protocol )
158- /* De facto standard: separate messages by a newline */
156+ /* Tenth: Optional newline message separator, if not implicitly terminated by end of UDP frame
157+ * De facto standard: separate messages by a newline
158+ */
159+ if (m -> protocol == SYSLOG_TRANSMISSION_PROTOCOL_TCP )
159160 IOVEC_SET_STRING (iov [n ++ ], "\n" );
160- else if (SYSLOG_TRANSMISSION_PROTOCOL_UDP == m -> protocol ) {
161- /* Message is implicitly terminated by end of UDP packet */
162- } else
163- return - EPROTONOSUPPORT ;
164161
165162 return network_send (m , iov , n );
166163}
167164
168165void manager_close_network_socket (Manager * m ) {
169166 assert (m );
170167
171- switch (m -> protocol ) {
172- case SYSLOG_TRANSMISSION_PROTOCOL_UDP :
173- /* shutdown not required */
174- break ;
175- case SYSLOG_TRANSMISSION_PROTOCOL_TCP :
176- {
177- int r = shutdown (m -> socket , SHUT_RDWR );
178- if (r < 0 )
179- log_error_errno (r , "Failed to shutdown netlog socket: %m" );
180- }
181- break ;
182- default :
183- break ;
168+ if (m -> protocol == SYSLOG_TRANSMISSION_PROTOCOL_TCP ) {
169+ int r = shutdown (m -> socket , SHUT_RDWR );
170+ if (r < 0 )
171+ log_error_errno (r , "Failed to shutdown netlog socket: %m" );
184172 }
185173
186174 m -> socket = safe_close (m -> socket );
@@ -208,10 +196,12 @@ int manager_open_network_socket(Manager *m) {
208196 if (m -> socket < 0 )
209197 return - errno ;
210198
211- r = setsockopt (m -> socket , IPPROTO_IP , IP_MULTICAST_LOOP , & one , sizeof (one ));
212- if (r < 0 ) {
213- r = - errno ;
214- goto fail ;
199+ if (m -> protocol == SYSLOG_TRANSMISSION_PROTOCOL_UDP ) {
200+ r = setsockopt (m -> socket , IPPROTO_IP , IP_MULTICAST_LOOP , & one , sizeof (one ));
201+ if (r < 0 ) {
202+ r = - errno ;
203+ goto fail ;
204+ }
215205 }
216206
217207 if (SYSLOG_TRANSMISSION_PROTOCOL_TCP == m -> protocol ) {
@@ -239,7 +229,7 @@ int manager_open_network_socket(Manager *m) {
239229 goto fail ;
240230 }
241231 r = connect (m -> socket , & m -> address .sockaddr .sa , salen );
242- if (r < 0 ) {
232+ if (r < 0 && errno != EINPROGRESS ) {
243233 r = - errno ;
244234 goto fail ;
245235 }
@@ -257,6 +247,5 @@ int manager_open_network_socket(Manager *m) {
257247
258248 fail :
259249 m -> socket = safe_close (m -> socket );
260-
261250 return r ;
262251}
0 commit comments