You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Sébastien Mizrahi <sm...@v3d.fr> on 2020/06/04 10:19:21 UTC

Re: TCP socket wothout HTTP protocol

Another not desired behavior related :

The ap_hook_process_connection is not called until client stops. In the client, the

Seb.
Le 14 avr. 2020 à 19:46 +0200, Sébastien Mizrahi <sm...@v3d.fr>, a écrit :
Hey Eric just a feedback to confirm that it just works as expected.
Thanks again !

Client from https://www.geeksforgeeks.org/socket-programming-cc/

Apache module :
int socket_process_connection(conn_rec *req) {
printf(« Conn init\n");
apr_socket_t *asock = ap_get_conn_socket(req);
int fd = 0;
apr_os_sock_get(&fd, asock);
char buffer[1024] = {0};
int valread = read(fd , buffer, 1024);
printf("%s\n", buffer);
return 0;
}

// Apache callback to register our hooks
void register_hooks(apr_pool_t* pool) {
static const char* const mod_ssl_reqtimeout[] = {"mod_ssl.c", "mod_reqtimeout.c", NULL};
ap_hook_process_connection(socket_process_connection, NULL, mod_ssl_reqtimeout, APR_HOOK_REALLY_FIRST);
}

Sebastien.

Le 14 avr. 2020 à 17:40 +0200, Sébastien Mizrahi <sm...@v3d.fr>, a écrit :
Thanks a lor Eric !

Gonna read this :)
Le 14 avr. 2020 à 17:20 +0200, Eric Covener <co...@gmail.com>, a écrit :
On Tue, Apr 14, 2020 at 11:16 AM Sébastien Mizrahi <sm...@v3d.fr> wrote:

Hi,

For some reasons, I would like to read natively TCP socket in an Apache module. The request is not encapsulated in HTTP protocol end the client send raw data.
I have already an apache module that manage standard HTTP request and I would like to mutualise the code.


The test suite has "weird" modules that are not HTTP that you might
have a look at

https://svn.apache.org/repos/asf/httpd/test/framework/trunk

./c-modules/nntp_like/mod_nntp_like.c is what I was thinking of. Just
from seeing it scroll by.

There is also mod_ftp: https://httpd.apache.org/mod_ftp/

Re: TCP socket wothout HTTP protocol

Posted by Sébastien Mizrahi <sm...@v3d.fr>.
Thanks Yann that was exactly what I was looking for ! Now works great !
Le 4 juin 2020 à 12:50 +0200, Yann Ylavic <yl...@gmail.com>, a écrit :
On Thu, Jun 4, 2020 at 12:26 PM Sébastien Mizrahi <sm...@v3d.fr> wrote:

In apache, the ap_hook_process_connection is not called until content is sent on socket, ap_hook_pre_connection and ap_hook_create_connection are called only after 10 seconds in this case. I would like to have a hook called when the connection is established.
Any (other hooks) way to do that ?

You probably should configure:
AcceptFilter http none
AcceptFilter https none

See https://httpd.apache.org/docs/2.4/en/mod/core.html#acceptfilter

Regards;
Yann.

Re: TCP socket wothout HTTP protocol

Posted by Yann Ylavic <yl...@gmail.com>.
On Thu, Jun 4, 2020 at 12:26 PM Sébastien Mizrahi <sm...@v3d.fr> wrote:
>
> In apache, the ap_hook_process_connection is not called until content is sent on socket, ap_hook_pre_connection and ap_hook_create_connection are called only after 10 seconds in this case. I would like to have a hook called when the connection is established.
> Any (other hooks) way to do that ?

You probably should configure:
   AcceptFilter http none
   AcceptFilter https none

See https://httpd.apache.org/docs/2.4/en/mod/core.html#acceptfilter

Regards;
Yann.

Re: TCP socket wothout HTTP protocol

Posted by Sébastien Mizrahi <sm...@v3d.fr>.
[sorry mail has been sent too quick]

Another not desired behavior related :

The ap_hook_process_connection is not called until client stops. In the client, got this code :

int main(int argc, char const *argv[])
{
int sockfd, connfd;
struct sockaddr_in servaddr, cli;

sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
printf("socket creation failed...\n");
exit(0);
}
else
printf("Socket successfully created..\n");
bzero(&servaddr, sizeof(servaddr));

servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
servaddr.sin_port = htons(90);

if (connect(sockfd, (const sockaddr*)&servaddr, sizeof(servaddr)) != 0) {
printf("connection with the server failed...\n");
exit(0);
}
else
printf("connected to the server..\n");

sleep(10);
}

In apache, the ap_hook_process_connection is not called until content is sent on socket, ap_hook_pre_connection and ap_hook_create_connection are called only after 10 seconds in this case. I would like to have a hook called when the connection is established.
Any (other hooks) way to do that ?

Sebastien.
Le 4 juin 2020 à 12:19 +0200, smizrahi@v3d.fr, a écrit :
Another not desired behavior related :

The ap_hook_process_connection is not called until client stops. In the client, the

Seb.
Le 14 avr. 2020 à 19:46 +0200, Sébastien Mizrahi <sm...@v3d.fr>, a écrit :
Hey Eric just a feedback to confirm that it just works as expected.
Thanks again !

Client from https://www.geeksforgeeks.org/socket-programming-cc/

Apache module :
int socket_process_connection(conn_rec *req) {
printf(« Conn init\n");
apr_socket_t *asock = ap_get_conn_socket(req);
int fd = 0;
apr_os_sock_get(&fd, asock);
char buffer[1024] = {0};
int valread = read(fd , buffer, 1024);
printf("%s\n", buffer);
return 0;
}

// Apache callback to register our hooks
void register_hooks(apr_pool_t* pool) {
static const char* const mod_ssl_reqtimeout[] = {"mod_ssl.c", "mod_reqtimeout.c", NULL};
ap_hook_process_connection(socket_process_connection, NULL, mod_ssl_reqtimeout, APR_HOOK_REALLY_FIRST);
}

Sebastien.

Le 14 avr. 2020 à 17:40 +0200, Sébastien Mizrahi <sm...@v3d.fr>, a écrit :
Thanks a lor Eric !

Gonna read this :)
Le 14 avr. 2020 à 17:20 +0200, Eric Covener <co...@gmail.com>, a écrit :
On Tue, Apr 14, 2020 at 11:16 AM Sébastien Mizrahi <sm...@v3d.fr> wrote:

Hi,

For some reasons, I would like to read natively TCP socket in an Apache module. The request is not encapsulated in HTTP protocol end the client send raw data.
I have already an apache module that manage standard HTTP request and I would like to mutualise the code.


The test suite has "weird" modules that are not HTTP that you might
have a look at

https://svn.apache.org/repos/asf/httpd/test/framework/trunk

./c-modules/nntp_like/mod_nntp_like.c is what I was thinking of. Just
from seeing it scroll by.

There is also mod_ftp: https://httpd.apache.org/mod_ftp/