Skip to content

Commit 35ef5bd

Browse files
caiiiycukTheldus
authored andcommitted
toyws: cpp compability; return frame length on tws_receiveframe
1 parent 312f112 commit 35ef5bd

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

extra/toyws/toyws.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static int skip_frame(struct tws_ctx *ctx, uint64_t frame_size)
318318
* @param buff_size Buffer size.
319319
* @param frm_type Frame type received.
320320
*
321-
* @return Returns 0 if success, a negative number
321+
* @return Returns frame length if success, a negative number
322322
* otherwise.
323323
*/
324324
int tws_receiveframe(struct tws_ctx *ctx, char **buff,
@@ -397,7 +397,7 @@ int tws_receiveframe(struct tws_ctx *ctx, char **buff,
397397
{
398398
cur_byte = next_byte(ctx, &ret);
399399
if (cur_byte < 0)
400-
return (ret);
400+
return (ret == 0 ? frame_length : ret);
401401

402402
*buf = cur_byte;
403403
}
@@ -406,5 +406,5 @@ int tws_receiveframe(struct tws_ctx *ctx, char **buff,
406406
/* Fill other infos. */
407407
*frm_type = opcode;
408408

409-
return (ret);
409+
return (ret == 0 ? frame_length : ret);
410410
}

extra/toyws/toyws.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
int fd;
4444
};
4545

46+
#ifdef __cplusplus
47+
extern "C" {
48+
#endif
49+
4650
/* External functions. */
4751
extern int tws_connect(struct tws_ctx *ctx, const char *ip,
4852
uint16_t port);
@@ -52,4 +56,8 @@
5256
extern int tws_receiveframe(struct tws_ctx *ctx, char **buff,
5357
size_t *buff_size, int *frm_type);
5458

59+
#ifdef __cplusplus
60+
}
61+
#endif
62+
5563
#endif /* TOYWS_H */

0 commit comments

Comments
 (0)