Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdbool.h>
- #include <stdio.h>
- #include <string.h>
- #include <sys/iomsg.h>
- #include <sys/neutrino.h>
- #include <unistd.h>
- #include "httpd_pid.h"
- char input[65535], response[65535];
- int main(void) {
- FILE* f = fopen(HTTPD_PID, "r");
- if (!f) {
- fputs("Cannot open \"" HTTPD_PID "\"\n", stderr);
- return 1;
- }
- int nodeDescriptor, serverId, channelId;
- bool ok = fscanf(f, "%d/%d/%d", &nodeDescriptor, &serverId, &channelId) == 3;
- fclose(f);
- if (!ok) {
- fputs("Invalid file format\n", stderr);
- return 1;
- }
- int connectionId = ConnectAttach(nodeDescriptor, serverId, channelId, 0, 0);
- if (connectionId == -1) {
- fputs("Server is not found\n", stderr);
- return 1;
- }
- while (fputs(">>> ", stdout) >= 0 && fgets(input, sizeof input / sizeof(char), stdin)) {
- int len = strlen(input);
- input[len - 1] = '\0';
- if (!strcmp(input, "exit"))
- break;
- if (MsgSend(connectionId, input, len, response, sizeof response) == -1) {
- fputs("Cannot send a message\n", stderr);
- return 1;
- }
- puts(response);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement