summaryrefslogtreecommitdiff
path: root/xmpp.c
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-12-04 14:04:06 +0100
committerxengineering <me@xengineering.eu>2023-01-08 18:43:01 +0100
commit271a8baaeb5cbd19047c50681d955c14115fc86f (patch)
tree95ee8dbf8bf6288d1da09d15f9a4d39a129c6360 /xmpp.c
parent9e2a44364bfae9a226e02fe7ddad032b16a1318f (diff)
downloadlimox-271a8baaeb5cbd19047c50681d955c14115fc86f.tar
limox-271a8baaeb5cbd19047c50681d955c14115fc86f.tar.zst
limox-271a8baaeb5cbd19047c50681d955c14115fc86f.zip
Connect on mouse click
With this commit the client starts the connection to the server as soon as the user clicks into the application window. Disconnect or reading / writing to the stream is not implemented.
Diffstat (limited to 'xmpp.c')
-rw-r--r--xmpp.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/xmpp.c b/xmpp.c
index c574ba5..dcf19a5 100644
--- a/xmpp.c
+++ b/xmpp.c
@@ -135,11 +135,11 @@ int xmpp_start_stream(int sock_fd, char *jid, char *domainpart)
}
/*
- * Initialize the network connection to the XMPP server
+ * Initialize the network connection to the XMPP server and return socket fd
*
* TODO: Error handling is missing.
*/
-void xmpp_connect(void)
+int xmpp_connect(void)
{
printf("net_init()\n");
@@ -155,36 +155,38 @@ void xmpp_connect(void)
int sock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
if (sock == -1) {
printf("Failed to get socket from OS!.");
- return;
+ return sock;
} else {
printf("Got socket number %d from OS.\n", sock);
}
if (connect(sock, addr->ai_addr, addr->ai_addrlen) == -1) {
printf("Failed to connect!\n");
- return;
+ return sock;
} else {
printf("Successfully connected.\n");
}
if (xmpp_start_stream(sock, jid, domain) == -1) {
printf("Failed to init stream!\n");
- return;
+ return sock;
}
printf("Stream init sent.\n");
- printf("This is the server response:\n");
- char buf;
- while(1) {
- int retval = recv(sock, (void *)&buf, 1, 0);
- if (retval == 0) {
- printf("Connection closed!\n");
- break;
- } else if (retval == 1) {
- write(1, (const void *)&buf, 1);
- } else {
- printf(strerror(errno));
- printf("Unhandled recv() return value %d!\n", retval);
- }
- }
+ return sock;
+
+// printf("This is the server response:\n");
+// char buf;
+// while(1) {
+// int retval = recv(sock, (void *)&buf, 1, 0);
+// if (retval == 0) {
+// printf("Connection closed!\n");
+// break;
+// } else if (retval == 1) {
+// write(1, (const void *)&buf, 1);
+// } else {
+// printf(strerror(errno));
+// printf("Unhandled recv() return value %d!\n", retval);
+// }
+// }
}