Lines Matching defs:conn

83 crUDPIPWriteExact( CRConnection *conn, const void *buf, unsigned int len )
86 if ( len > conn->mtu + sizeof(conn->seq) )
88 crWarning( "crUDPIPWriteExact(%d): too big a packet for mtu %d, dropping !", len, (int)(conn->mtu + sizeof(conn->seq)) );
91 retval = sendto( conn->udp_socket, buf, len, 0,
92 (struct sockaddr *) &(conn->remoteaddr), sizeof(conn->remoteaddr));
103 if ( getsockopt( conn->udp_socket, SOL_IP, IP_MTU_DISCOVER, &opt, &leno) == -1)
119 if ( getsockopt( conn->udp_socket, SOL_IP, IP_MTU, &opt, &leno) == -1 )
130 opt -= sizeof(conn->seq) + sizeof(struct udphdr) + sizeof(struct ip6_hdr);
131 if (opt >= (int) conn->mtu)
133 crWarning( "But MTU discovery is still bigger ! Narrowing it by hand to %d", conn->mtu = (conn->mtu * 2 / 3) & ~0x3 );
138 conn->mtu = opt & ~0x3;
146 crUDPTCPIPAccept( CRConnection *conn, const char *hostname, unsigned short port )
159 crTCPIPAccept( conn, hostname, port );
162 conn->udp_socket = socket( AF_INET, SOCK_DGRAM, 0 );
163 if ( conn->udp_socket >= 0 )
169 if ( bind( conn->udp_socket, (struct sockaddr *) &udpaddr, sizeof(udpaddr) ) )
173 crCloseSocket( conn->udp_socket );
174 conn->udp_socket = -1;
187 conn->udp_socket = -1;
191 conn->udp_socket = socket( cur->ai_family, cur->ai_socktype, cur->ai_protocol );
192 if ( conn->udp_socket == -1 )
199 if ( bind( conn->udp_socket, cur->ai_addr, cur->ai_addrlen ) )
203 crCloseSocket( conn->udp_socket );
204 conn->udp_socket = -1;
213 if ( conn->udp_socket < 0 )
217 err = getsockname( conn->udp_socket, (struct sockaddr *) &addr, &addr_length );
224 crTCPIPWriteExact( conn, &((struct sockaddr_in *)&addr)->sin_port,
229 crTCPIPWriteExact( conn, &((struct sockaddr_in6 *)&addr)->sin6_port,
240 static void crUDPTCPIPSend( CRConnection *conn, void **bufp,
247 if ( !conn || conn->type == CR_NO_CONNECTION )
260 conn->seq++;
263 unsigned int len_swap = conn->swap ? SWAP32(len) : len;
267 crTCPIPWriteExact( conn, &len_swap, sizeof(len_swap) );
268 if ( !conn || conn->type == CR_NO_CONNECTION ) return;
269 crTCPIPWriteExact( conn, start, len );
282 if (conn->swap)
291 if ( __tcpip_write_exact( conn->tcp_socket, lenp, len + sizeof(*lenp) ) < 0 )
293 __tcpip_dead_connection( conn );
301 crBufferPoolPush( cr_tcpip.bufpool, udptcpip_buffer, conn->buffer_size );
313 static void crUDPTCPIPBarf( CRConnection *conn, void **bufp,
330 crUDPTCPIPSend( conn, bufp, start, len);
333 if (len > conn->mtu) {
334 crDebug("writing safely %d bytes because that is too much for MTU %d", len, conn->mtu);
335 crUDPTCPIPSend( conn, bufp, start, len);
364 if (conn->swap)
366 *seqp = SWAP32(conn->seq);
370 *seqp = conn->seq;
372 crUDPIPWriteExact( conn, seqp, len + sizeof(*seqp) );
379 crBufferPoolPush( cr_tcpip.bufpool, udptcpip_buffer, conn->buffer_size );
387 crUDPTCPIPReceive( CRConnection *conn, CRTCPIPBuffer *buf, int len )
395 conn->recv_credits -= len;
397 conn->total_bytes_recv += len;
401 if (conn->swap)
407 crNetDispatchMessage( cr_tcpip.recv_list, conn, msg, len );
415 crTCPIPFree( conn, buf + 1 );
436 CRConnection *conn = cr_tcpip.conns[i];
437 if ( !conn || conn->type == CR_NO_CONNECTION ) continue;
438 if ( conn->recv_credits > 0 || conn->type != CR_UDPTCPIP )
447 CRSocket sock = conn->tcp_socket;
449 if (conn->type != CR_UDPTCPIP)
456 sock = conn->udp_socket;
489 CRConnection *conn = cr_tcpip.conns[i];
494 if ( !conn || conn->type == CR_NO_CONNECTION ) continue;
496 if ( conn->type != CR_UDPTCPIP )
499 if ( conn->udp_packet ) {
501 buf = conn->udp_packet;
503 if ( *seq == conn->ack )
505 crUDPTCPIPReceive( conn, buf,
506 conn->udp_packetlen );
507 conn->udp_packet = NULL;
511 if ( *seq - conn->ack > (~(0U)) >> 1 )
513 crError( "%u is older than %u ?!", *seq, conn->ack );
514 crTCPIPFree( conn, buf + 1 );
515 conn->udp_packet = NULL;
521 else if ( FD_ISSET(conn->udp_socket, &read_fds ) )
523 CRTCPIPBuffer *buf = ((CRTCPIPBuffer *) crTCPIPAlloc( conn )) - 1;
527 len = recv( conn->udp_socket, (void *)seq,
535 crTCPIPFree( conn, buf + 1 );
541 if ( *seq == conn->ack)
543 crUDPTCPIPReceive( conn, buf, len );
547 if ( *seq - conn->ack > (~(0U)) >> 1 )
549 crWarning( "%u is older than %u, dropping", *seq, conn->ack );
550 crTCPIPFree( conn, buf + 1 );
553 conn->udp_packet = buf;
554 conn->udp_packetlen = len;
557 sock = conn->tcp_socket;
563 __tcpip_dead_connection( conn );
568 if (conn->swap)
575 if ( (unsigned int)len <= conn->buffer_size )
577 buf = (CRTCPIPBuffer *) crTCPIPAlloc( conn ) - 1;
594 __tcpip_dead_connection( conn );
599 crUDPTCPIPReceive( conn, buf, len );
600 conn->ack++;
618 static int crUDPTCPIPDoConnect( CRConnection *conn )
638 if ( !crTCPIPDoConnect( conn ) )
642 crTCPIPReadExact( conn, &port, sizeof( port ) );
649 hp = gethostbyname( conn->hostname );
652 crWarning( "Unknown host: \"%s\"", conn->hostname );
655 conn->udp_socket = socket( AF_INET, SOCK_DGRAM, 0 );
656 memset(&conn->remoteaddr, 0, sizeof(conn->remoteaddr));
657 conn->remoteaddr.sin_family = AF_INET;
658 conn->remoteaddr.sin_port = htons( (short) port );
660 memcpy( (char *) &conn->remoteaddr.sin_addr, hp->h_addr,
661 sizeof(conn->remoteaddr.sin_addr) );
662 if ( conn->udp_socket >= 0 ) {
663 if ( connect( conn->udp_socket, (struct sockaddr *) &conn->remoteaddr,
664 sizeof(conn->remoteaddr) ) == -1 )
674 err = getaddrinfo( conn->hostname, port_s, &hints, &res);
677 crWarning( "Unknown host: \"%s\": %s", conn->hostname, gai_strerror(err) );
683 conn->udp_socket = socket( cur->ai_family, cur->ai_socktype, cur->ai_protocol );
684 if ( conn->udp_socket >= 0 )
686 if ( connect( conn->udp_socket, cur->ai_addr, cur->ai_addrlen ) == -1 )
698 crWarning( "Couldn't find any suitable way to connect to %s:%d", conn->hostname, port );
703 if ( setsockopt(conn->udp_socket, SOL_IP, IP_MTU_DISCOVER, &opt, sizeof(opt)) == -1 )
711 if ( getsockopt(conn->udp_socket, SOL_IP, IP_MTU, &opt, &len) == -1 )
718 opt -= sizeof(conn->seq) + sizeof(struct udphdr) + sizeof(struct ip6_hdr);
720 conn->mtu = opt;
725 crMemcpy(&conn->remoteaddr, cur->ai_addr, cur->ai_addrlen);
731 static void crUDPTCPIPDoDisconnect( CRConnection *conn )
733 crCloseSocket( conn->udp_socket );
734 crTCPIPDoDisconnect( conn );
737 void crUDPTCPIPConnection( CRConnection *conn )
739 crTCPIPConnection( conn );
741 conn->type = CR_UDPTCPIP;
742 conn->Send = crUDPTCPIPSend;
743 conn->Barf = crUDPTCPIPBarf;
744 conn->SendExact = NULL;
745 conn->Recv = NULL; /* none for UDP : *must* multiplex ! */
746 conn->Accept = crUDPTCPIPAccept;
747 conn->Connect = crUDPTCPIPDoConnect;
748 conn->Disconnect = crUDPTCPIPDoDisconnect;
749 conn->seq = 0;
750 conn->ack = 0;
751 conn->udp_packet = NULL;
752 conn->mtu -= sizeof(conn->seq); /* some room for seq */