Browse code

core: Fixed a problem with receiving WebSocket frames

- If two frames were pulled from the buffer at the same time the second
wasn't being processed.

Peter Dunkley authored on 17/06/2012 20:30:33
Showing 1 changed files
... ...
@@ -1018,14 +1018,18 @@ int msrp_process_msg(char* tcpbuf, unsigned int len,
1018 1018
 #ifdef READ_WS
1019 1019
 static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1020 1020
 {
1021
-	int bytes, pos, mask_present;
1021
+	int bytes, size, pos, mask_present;
1022 1022
 	unsigned int len;
1023 1023
 	char *p;
1024 1024
 	struct tcp_req *r;
1025 1025
 
1026 1026
 	r=&c->req;
1027 1027
 	if (unlikely(r->parsed < r->pos))
1028
+	{
1029
+		LM_ERR("next frame...\n");
1028 1030
 		bytes = 0;
1031
+		size = r->pos - r->parsed;
1032
+	}
1029 1033
 	else
1030 1034
 	{
1031 1035
 #ifdef USE_TLS
... ...
@@ -1035,10 +1039,10 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1035 1039
 #endif
1036 1040
 			bytes = tcp_read(c, read_flags);
1037 1041
 
1038
-		LM_INFO("read %d bytes\n", bytes);
1039
-
1040 1042
 		if (bytes <= 0)
1041 1043
 			return 0;
1044
+
1045
+		size = bytes;
1042 1046
 	}
1043 1047
 
1044 1048
 	p = r->parsed;
... ...
@@ -1069,7 +1073,7 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1069 1073
 	*/
1070 1074
 
1071 1075
 	/* Process first two bytes */
1072
-	if (bytes < pos + 2)
1076
+	if (size < pos + 2)
1073 1077
 		goto skip;
1074 1078
 	pos++;
1075 1079
 	mask_present = p[pos] & 0x80;
... ...
@@ -1078,7 +1082,7 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1078 1082
 	/* Work out real length */
1079 1083
 	if (len == 126)
1080 1084
 	{
1081
-		if (bytes < pos + 2)
1085
+		if (size < pos + 2)
1082 1086
 			goto skip;
1083 1087
 
1084 1088
 		len =	  ((p[pos + 0] & 0xff) <<  8)
... ...
@@ -1087,7 +1091,7 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1087 1091
 	}
1088 1092
 	else if (len == 127)
1089 1093
 	{
1090
-		if (bytes < pos + 8)
1094
+		if (size < pos + 8)
1091 1095
 			goto skip;
1092 1096
 
1093 1097
 		/* Only decoding the last four bytes of the length...
... ...
@@ -1103,17 +1107,16 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1103 1107
 	/* Skip mask */
1104 1108
 	if (mask_present)
1105 1109
 	{
1106
-		if (bytes < pos + 4)
1110
+		if (size < pos + 4)
1107 1111
 			goto skip;
1108 1112
 		pos += 4;
1109 1113
 	}
1110 1114
 
1111 1115
 	/* Now check the whole message has been received */
1112
-	if (bytes < pos + len)
1116
+	if (size < pos + len)
1113 1117
 		goto skip;
1114 1118
 
1115 1119
 	pos += len;
1116
-	r->bytes_to_go = bytes - pos;
1117 1120
 	r->flags |= F_TCP_REQ_COMPLETE;
1118 1121
 	r->parsed = &p[pos];
1119 1122