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 1035
 #endif
1036 1036
 			bytes = tcp_read(c, read_flags);
1037 1037
 
1038
-		LM_INFO("read %d bytes\n", bytes);
1039
-
1040 1038
 		if (bytes <= 0)
1041 1039
 			return 0;
1040
+
1041
+		size = bytes;
1042 1042
 	}
1043 1043
 
1044 1044
 	p = r->parsed;
... ...
@@ -1069,7 +1073,7 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1069 1069
 	*/
1070 1070
 
1071 1071
 	/* Process first two bytes */
1072
-	if (bytes < pos + 2)
1072
+	if (size < pos + 2)
1073 1073
 		goto skip;
1074 1074
 	pos++;
1075 1075
 	mask_present = p[pos] & 0x80;
... ...
@@ -1078,7 +1082,7 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1078 1078
 	/* Work out real length */
1079 1079
 	if (len == 126)
1080 1080
 	{
1081
-		if (bytes < pos + 2)
1081
+		if (size < pos + 2)
1082 1082
 			goto skip;
1083 1083
 
1084 1084
 		len =	  ((p[pos + 0] & 0xff) <<  8)
... ...
@@ -1087,7 +1091,7 @@ static int tcp_read_ws(struct tcp_connection *c, int* read_flags)
1087 1087
 	}
1088 1088
 	else if (len == 127)
1089 1089
 	{
1090
-		if (bytes < pos + 8)
1090
+		if (size < pos + 8)
1091 1091
 			goto skip;
1092 1092
 
1093 1093
 		/* 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 1103
 	/* Skip mask */
1104 1104
 	if (mask_present)
1105 1105
 	{
1106
-		if (bytes < pos + 4)
1106
+		if (size < pos + 4)
1107 1107
 			goto skip;
1108 1108
 		pos += 4;
1109 1109
 	}
1110 1110
 
1111 1111
 	/* Now check the whole message has been received */
1112
-	if (bytes < pos + len)
1112
+	if (size < pos + len)
1113 1113
 		goto skip;
1114 1114
 
1115 1115
 	pos += len;
1116
-	r->bytes_to_go = bytes - pos;
1117 1116
 	r->flags |= F_TCP_REQ_COMPLETE;
1118 1117
 	r->parsed = &p[pos];
1119 1118