Skip to content

Commit

Permalink
add the retry
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzhenyu committed Dec 1, 2017
1 parent 9c8494a commit 7839b19
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion sub_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void error_handling(char* message);
void error_handling(char* message) {
fputs(message, stderr);
fputc('\n', stderr);
exit(1);
//exit(1);
}
int readI16(const unsigned char * pData, uint16_t *pValue)
{
Expand Down Expand Up @@ -70,6 +70,7 @@ sock connect_nsqd_with_lookupd(const char *address, const char* port){
//把socket和socket地址结构联系起来
if( connect(sock,(struct sockaddr*)&serv_addr,sizeof(serv_addr)) == -1) {
error_handling("connect() error");
return 0;
}
return sock;

Expand Down
12 changes: 11 additions & 1 deletion sub_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,24 @@ int msg_callback_m(struct NSQMessage *msg){
int main()
{
int sock;
connect:
sock = connect_nsqd_with_lookupd("127.0.0.1", "4150"); //现在只是 直连nsqd 的地址,lookupd地址支持 以后上
printf("sock:%d",sock);
if(!sock){
goto connect;

}
struct NSQMessage *msg;
msg = (struct NSQMessage *)malloc(sizeof(struct NSQMessage));
msg->topic = "test";
msg->channel = "struggle";
msg->rdy = 2;
int (*msg_callback)(struct NSQMessage *msg) = msg_callback_m;
subscribe(sock, msg, msg_callback);
int re = subscribe(sock, msg, msg_callback);
printf("re:%d",re);
if(!re){
goto connect;
}
free(msg);

}
Expand Down

0 comments on commit 7839b19

Please sign in to comment.