clean up ecore-con server example: HTTP requires a seperator (\r\n in this case)...
authordiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 16 Jul 2011 08:01:19 +0000 (08:01 +0000)
committerdiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 16 Jul 2011 08:01:19 +0000 (08:01 +0000)
snprintf use here is incorrect due to inconsistent behavior of snprintf, so we can lazily fall back to strlen since this is just a simple example

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/ecore@61421 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/examples/ecore_con_server_http_example.c

index fec6a1a..d3fdeee 100644 (file)
@@ -14,11 +14,10 @@ static const char response_template[] =
 "Server: Ecore_Con custom server\r\n"
 "Content-Length: %zd\r\n"
 "Content-Type: text/html; charset=UTF-8\r\n"
-"Set-Cookie: MYCOOKIE=1; path=/; expires=%s"
+"Set-Cookie: MYCOOKIE=1; path=/; expires=%s\r\n"
 "Set-Cookie: SESSIONCOOKIE=1; path=/\r\n"
 "\r\n"
-"%s"
-"\r\n\r\n";
+"%s";
 
 struct _Client {
     int sdata;
@@ -31,7 +30,6 @@ _add(void *data __UNUSED__, int type __UNUSED__, Ecore_Con_Event_Client_Add *ev)
    client->sdata = 0;
    static char buf[4096];
    char welcome[] = "Welcome to Ecore_Con server!";
-   int nbytes;
    time_t t;
 
    printf("Client with ip %s, port %d, connected = %d!\n",
@@ -43,9 +41,9 @@ _add(void *data __UNUSED__, int type __UNUSED__, Ecore_Con_Event_Client_Add *ev)
 
    t = time(NULL);
    t += 60 * 60 * 24;
-   nbytes = snprintf(buf, sizeof(buf), response_template, sizeof(welcome), ctime(&t), welcome);
+   snprintf(buf, sizeof(buf), response_template, sizeof(welcome) - 1, ctime(&t), welcome);
 
-   ecore_con_client_send(ev->client, buf, nbytes);
+   ecore_con_client_send(ev->client, buf, strlen(buf));
    ecore_con_client_flush(ev->client);