comparison libgaim/protocols/oscar/flap_connection.c @ 15195:4934e7a03a98

[gaim-migrate @ 17983] Move away from using MSG_PEEK when recv'ing data over oscar sockets. It's possible this was causing problems with a small number of Windows users? People seem to frown pretty heavily upon MSG_PEEK in general, for some reason. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Wed, 13 Dec 2006 10:11:31 +0000
parents 8138277e9369
children 00d0d4524377
comparison
equal deleted inserted replaced
15194:8d2e6e9118e2 15195:4934e7a03a98
768 void 768 void
769 flap_connection_recv_cb(gpointer data, gint source, GaimInputCondition cond) 769 flap_connection_recv_cb(gpointer data, gint source, GaimInputCondition cond)
770 { 770 {
771 FlapConnection *conn; 771 FlapConnection *conn;
772 ssize_t read; 772 ssize_t read;
773 guint8 header[6];
774 773
775 conn = data; 774 conn = data;
776 775
777 /* Read data until we run out of data and break out of the loop */ 776 /* Read data until we run out of data and break out of the loop */
778 while (TRUE) 777 while (TRUE)
779 { 778 {
780 /* Start reading a new FLAP */ 779 /* Start reading a new FLAP */
781 if (conn->buffer_incoming.data.data == NULL) 780 if (conn->buffer_incoming.data.data == NULL)
782 { 781 {
783 /* Peek at the first 6 bytes to get the length */ 782 /* Read the first 6 bytes (the FLAP header) */
784 read = recv(conn->fd, &header, 6, MSG_PEEK); 783 read = recv(conn->fd, conn->header + conn->header_received,
784 6 - conn->header_received, 0);
785 785
786 /* Check if the FLAP server closed the connection */ 786 /* Check if the FLAP server closed the connection */
787 if (read == 0) 787 if (read == 0)
788 { 788 {
789 flap_connection_schedule_destroy(conn, 789 flap_connection_schedule_destroy(conn,
803 OSCAR_DISCONNECT_LOST_CONNECTION, strerror(errno)); 803 OSCAR_DISCONNECT_LOST_CONNECTION, strerror(errno));
804 break; 804 break;
805 } 805 }
806 806
807 /* If we don't even have a complete FLAP header then do nothing */ 807 /* If we don't even have a complete FLAP header then do nothing */
808 if (read < 6) 808 conn->header_received += read;
809 if (conn->header_received < 6)
809 break; 810 break;
810 811
811 /* Read the first 6 bytes (the FLAP header) */
812 read = recv(conn->fd, &header, 6, 0);
813
814 /* All FLAP frames must start with the byte 0x2a */ 812 /* All FLAP frames must start with the byte 0x2a */
815 if (aimutil_get8(&header[0]) != 0x2a) 813 if (aimutil_get8(&conn->header[0]) != 0x2a)
816 { 814 {
817 flap_connection_schedule_destroy(conn, 815 flap_connection_schedule_destroy(conn,
818 OSCAR_DISCONNECT_INVALID_DATA, NULL); 816 OSCAR_DISCONNECT_INVALID_DATA, NULL);
819 break; 817 break;
820 } 818 }
821 819
822 /* Verify the sequence number sent by the server. */ 820 /* Verify the sequence number sent by the server. */
823 #if 0 821 #if 0
824 /* TODO: Need to initialize conn->seqnum_in somewhere before we can use this. */ 822 /* TODO: Need to initialize conn->seqnum_in somewhere before we can use this. */
825 if (aimutil_get16(&header[1]) != conn->seqnum_in++) 823 if (aimutil_get16(&conn->header[1]) != conn->seqnum_in++)
826 { 824 {
827 /* Received an out-of-order FLAP! */ 825 /* Received an out-of-order FLAP! */
828 flap_connection_schedule_destroy(conn, 826 flap_connection_schedule_destroy(conn,
829 OSCAR_DISCONNECT_INVALID_DATA, NULL); 827 OSCAR_DISCONNECT_INVALID_DATA, NULL);
830 break; 828 break;
831 } 829 }
832 #endif 830 #endif
833 831
834 /* Initialize a new temporary FlapFrame for incoming data */ 832 /* Initialize a new temporary FlapFrame for incoming data */
835 conn->buffer_incoming.channel = aimutil_get8(&header[1]); 833 conn->buffer_incoming.channel = aimutil_get8(&conn->header[1]);
836 conn->buffer_incoming.seqnum = aimutil_get16(&header[2]); 834 conn->buffer_incoming.seqnum = aimutil_get16(&conn->header[2]);
837 conn->buffer_incoming.data.len = aimutil_get16(&header[4]); 835 conn->buffer_incoming.data.len = aimutil_get16(&conn->header[4]);
838 conn->buffer_incoming.data.data = g_new(guint8, conn->buffer_incoming.data.len); 836 conn->buffer_incoming.data.data = g_new(guint8, conn->buffer_incoming.data.len);
839 conn->buffer_incoming.data.offset = 0; 837 conn->buffer_incoming.data.offset = 0;
840 } 838 }
841 839
842 if (conn->buffer_incoming.data.len - conn->buffer_incoming.data.offset) 840 if (conn->buffer_incoming.data.len - conn->buffer_incoming.data.offset)
878 parse_flap(conn->od, conn, &conn->buffer_incoming); 876 parse_flap(conn->od, conn, &conn->buffer_incoming);
879 conn->lastactivity = time(NULL); 877 conn->lastactivity = time(NULL);
880 878
881 g_free(conn->buffer_incoming.data.data); 879 g_free(conn->buffer_incoming.data.data);
882 conn->buffer_incoming.data.data = NULL; 880 conn->buffer_incoming.data.data = NULL;
881
882 conn->header_received = 0;
883 } 883 }
884 } 884 }
885 885
886 static void 886 static void
887 send_cb(gpointer data, gint source, GaimInputCondition cond) 887 send_cb(gpointer data, gint source, GaimInputCondition cond)